Parent Process and Child Process - fork() in C/C++ Confuses Me! Can You End It For Me Please?

I'm new to multi-threading concepts. It confuses me alot.

I got several questions on this quote:

"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"

>> In modern computer operating systems, a process (or task) may wait on another process to complete its execution.

1. the idea of multi-threading is not implemented here since a process (parent process) is keep waiting on another process (child process) to complete its execution. right?

2. as it is known that a parent can have a child and this child can have new child and regarding question 1,  that every parent process is keep waiting its child. Eventually, we will have alot of processes waiting for the last appeared process to finish its execution. Does not make sense to me! can you clarify?

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

3. Isn't parent process creates a newly independent child process. So how come the parent process get suspended while the child executes?! I believe parent process can get suspended temporarily only when a child process exits. The goal of parent suspension is to grab the exit status. After that, parent should go back to its activity...That's how i know it! Please clarify if i'm wrong

4. Are parent process only responsible of creating child process and grab its exit status?
If no, then what kind of other activities parent process does?
If yes, then this kind of a problem because every child process can become a parent process! so we will end up having alot of parent processes who does nothing except grabbing exit status of its X child process & since that X child process can have another Y child, then X child is considered a parent who does nothing  grabbing exit status of its Y child process, and so on...It goes like a chain...please fix me!

>>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 parent process then resumes execution.***

5. This does not make sense, since its going to cost long time until the first parent process get executed, as i said it goes like a chain:

init -> process 2 -> process 3 -> process 4 -> process 5

3, 4, and 5 are all childs but 3 is a parent of 4 and 4 is a parent 5. The child that is executing right now is 5. 4 will have to wait until 5 finishes & then 4 does its job of execution. At this time 2, and 3 are still waiting & so on ....

Can you please explain it in a plain English language, because i always get confused in concepts of threads, childs, parents, etc....

I'm looking forward to hearing from you!
LVL 1
F-J-KAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sunnycoderCommented:
>>> In modern computer operating systems, a process (or task) may wait on another process to complete its execution.

>1. the idea of multi-threading is not implemented here since a process (parent process) is keep waiting on another process (child process) to complete its execution. right?

Multi-threading is a different concept altogether ... A thread is not the same as process. A thread is a light weight process.
http://en.wikipedia.org/wiki/Thread_(computer_science)

>2. as it is known that a parent can have a child and this child can have new child and regarding question 1,  that
>every parent process is keep waiting its child. Eventually, we will have alot of processes waiting for the last
>appeared process to finish its execution. Does not make sense to me! can you clarify?

Parent does not necessarily have to wait ... It *may* choose to wait by explicitly calling wait() or waitpid(). There are circumstances where you may want the child process to finish before parent proceeds. e.g. If child process creates a list of file on which the parent does processing. Parent cannot continue until child has finished execution. Hence parent will wait on child.

>3. Isn't parent process creates a newly independent child process.
Thats correct

>So how come the parent process get suspended while the child executes?!
It doesnt ... it may *choose* to wait.

>I believe parent process can get suspended temporarily only when a child process exits.
In the event of child exiting, SIGCHLD is sent to parent process. Parent may choose to ignore this signal or it may handle it. It is free to collect the exit status of child whenever it wishes to. Parent does not suspend.

>The goal of parent suspension is to grab the exit status. After that, parent should go back to its activity...That's
>how i know it! Please clarify if i'm wrong
I would not call it the goal of parent process but this is one of the things it should do. Your understanding is correct.

>4. Are parent process only responsible of creating child process and grab its exit status?
>If no, then what kind of other activities parent process does?
A parent process is a normal process .. it is free to do normal processing like all other processes

>If yes, then this kind of a problem because every child process can become a parent process! so we will end up
>having alot of parent processes who does nothing except grabbing exit status of its X child process & since that X
>child process can have another Y child, then X child is considered a parent who does nothing  grabbing exit status
>of its Y child process, and so on...It goes like a chain...please fix me!
Draw an analogy with humans ... A process (human) may or may not have children ... may have any number of them ... irrespective of number of children, every human (process) has a normal life (execution and processing) ... If a process has children, it is expected to collect their exit status in addition to normal execution.

>>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 parent process then resumes execution.***

>5. This does not make sense, since its going to cost long time until the first parent process get executed, as i said
>it goes like a chain:

>init -> process 2 -> process 3 -> process 4 -> process 5

>3, 4, and 5 are all childs but 3 is a parent of 4 and 4 is a parent 5. The child that is executing right now is 5. 4 will
>have to wait until 5 finishes & then 4 does its job of execution. At this time 2, and 3 are still waiting & so on ....

Should be answered by now.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
F-J-KAuthor Commented:
Well Done! I appreciate your help alot & you deserve the full points
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.