Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a child's PID?

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?

like image 789
Joe Fontana Avatar asked Dec 02 '25 21:12

Joe Fontana


2 Answers

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.

like image 125
www.aegisub.net Avatar answered Dec 07 '25 12:12

www.aegisub.net


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.

like image 37
wvdschel Avatar answered Dec 07 '25 12:12

wvdschel