Question

I am currently in an operating systems class and my teacher spent half of the class period talking about PIDs. She mentioned, as many know, that processes know their parent's ID.

My question is this:

Does a process's PCB know its child's ID? If so, what is the way to go about it obtaining it?

Was it helpful?

Solution

As far as I know a process doesn't have an explicit list of its children's PIDs, but it can easily be built, since a process should know which child processes it spawns. For example the UNIX fork() call returns the child PID in the parent process and 0 in the child process, CreateProcess() on Windows returns (IIRC) the PID of the new process created.

OTHER TIPS

When you use fork() on *nix, the return value is the PID of the child in the parent process, and 0 in the child process. That's one way to find out.

Not sure if they keep track of the "tree" of process spawning, I think it depends on what OS you use, but since when you kill bash (or any shell), all running children are also killed, I think UNIX like systems do keep track of this.

If you're using Linux or anything which implements the Unix APIs, when a process calls fork() to create a child process the parent receives the child PID as the return code, or -1 if the fork failed. The child process gets a zero return code.

Process's PCB know its child's ID.

As we know the Fork() is used to create processes.It takes no arguments and returns a process ID.After a new child process is created both parent and child will execute the next instruction following the fork(). There we have to distinguish the parent from the child.This can be done by testing the return value of fork().

If Fork() returns a negative value, the creation of child process is unsuccessful. If Fork() returns a Zero to the newly created child process. If Fork() returns a positive value as a process ID of the child process to the parent process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top