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?
-
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.
From wvdschel -
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.
From www.aegisub.net -
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.
From DGentry
0 comments:
Post a Comment