LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to make sure no orphans are created? (https://www.linuxquestions.org/questions/programming-9/how-to-make-sure-no-orphans-are-created-829038/)

whirlpool 08-28-2010 01:58 PM

How to make sure no orphans are created?
 
Iv been trying to solve a problem using C language.Iv worked out the logic. But being new to the linux commands Iv not been able to code it .There are two parts to my problem.

1) The first being, the parent process should create as many children (i.e.using fork() ) as desired by the user at run time without any of the children beginning their execution.
Here is what I thought : Stopping children from execution could be done using the condition if(fork()==0) { <the command to stop>)
Would sigstop be the command ?
Im unsure about it as I want the children to only stop their execution till the time parent finishes creating children. After which the children should begin their execution.



2) The second glitch where I'm stuck is , I do not want any orphans to be created so, a parent should enter a wait state till all it's children have finished execution. And then the parent can die.
How to implement this ? How do we enter and exit from wait states for specific pids? (the children's pid .. in this case ).


Please correct me if I'm on the wrong line of thought.

Thanks

Aquarius_Girl 08-28-2010 02:29 PM

Quote:

Originally Posted by whirlpool (Post 4080866)
I want the children to only stop their execution till the time parent finishes creating children...Would sigstop be the command ?

Welcome to LQ !

Check out the following links:
wait()
1. http://manpages.courier-mta.org/htmlman2/wait.2.html
2. http://www.csl.mtu.edu/cs4411/www/NO...fork/wait.html
3. http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html

sig family:
1. http://www.supercomputing.it/At_Cile.../sigset.2.html

Read these detailed descriptions, see if that helps !

Tinkster 08-29-2010 12:23 AM

Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.

whirlpool 08-29-2010 01:33 AM

Quote:

Originally Posted by anishakaul (Post 4080881)

Thanks a lot! It's with the help of people like you that beginners get encouraged to learn more. :)

Aquarius_Girl 08-29-2010 04:35 AM

Quote:

Originally Posted by whirlpool (Post 4081218)
Thanks a lot! It's with the help of people like you that beginners get encouraged to learn more. :)

I am really glad I could be of some help to you ! and you formed the question really well. Keep it up ! :)


All times are GMT -5. The time now is 03:29 PM.