<p>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.</p>

<p>My question is this:</p>

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

[{'answer_id': 60075, 'author': 'wvdschel', 'author_id': 2018, 'author_profile': 'https://Stackoverflow.com/users/2018', 'pm_score': 2, 'selected': False, 'text': '<p>When you use <code>fork()</code> 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.</p>\n\n<p>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.</p>\n'}, {'answer_id': 60077, 'author': 'www.aegisub.net', 'author_id': 6203, 'author_profile': 'https://Stackoverflow.com/users/6203', 'pm_score': 4, 'selected': True, 'text': "<p>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.</p>\n"}, {'answer_id': 60078, 'author': 'DGentry', 'author_id': 4761, 'author_profile': 'https://Stackoverflow.com/users/4761', 'pm_score': 2, 'selected': False, 'text': "<p>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.</p>\n"}, {'answer_id': 10578197, 'author': 'Sharad', 'author_id': 1391167, 'author_profile': 'https://Stackoverflow.com/users/1391167', 'pm_score': 1, 'selected': False, 'text': "<p>Process's PCB know its child's ID.</p>\n\n<p>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().\nThere we have to distinguish the parent from the child.This can be done by testing the return value of fork().</p>\n\n<p>If Fork() returns a negative value, the creation of child process is unsuccessful.\nIf Fork() returns a Zero to the newly created child process.\nIf Fork() returns a positive value as a process ID of the child process to the parent process.</p>\n"}]
['https://Stackoverflow.com/questions/60070', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/73/']