Questions About fork() & waitpid() .... C/C++ Socket Programming in Linux and Unix
Posted on 2008-11-10
"Waitpid() - In modern computer operating systems, a process (or task) may wait on another process to complete its execution. In most systems, a parent process can create an independently executing child process. The parent process may then issue a wait system call, which suspends the execution of the parent(its own) process while the child executes. When the child process terminates, it returns an exit status to the operating system, which is then returned to the waiting parent process. The parent process then resumes execution. The exit status returned by a child process typically indicates whether the process terminated normally or abnormally."
>>quote "The parent process then resumes execution."
1. What does it resume exactly? What kind of execuion?
"every process is created when another process executes the fork system call. The process that invoked fork is the parent process and the newly-created process is the child process. Every process has one parent process, but can have many child processes. The kernel identifies each process by its process identifier (PID). Process 0 is a special process that is created when the system boots; after forking a child process (process 1), process 0 becomes the swapper process & process 1, known as init, is the ancestor of every other process in the system."
>>quote "The process that invoked fork is the parent process and the newly-created process is the child process. Every process has one parent process, but can have many child processes. "
2. The process that invoked fork is the parent process. Does this mean
a child process and can create a new process?
Every process has one parent process. Parent process always has many child processes. and every child process can create another new child process which makes the first child process becomes a parent to the new child process, and in the same time it is considered a child process to its parent process. It is like a parent creates a child and child creates a new child! so the new child process has a parent of a child process who got another parent. It goes like a chain. Thats how i understand it. Is this right?
If yes, then
a. when the parent process will get a chance to create several child process who do not have another child process under them?
b. can you fix it for me please?