ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
in the heading list in ps -l, what do WCHAN, SZ, ADDR, NI, PRI, and C mean?? like the way F means for process flags...
Can someone plz explain the concept of "time slicing" with relation to the kernal scheduler??
in a program where you give 2 fork() commands, why is it important to have sleep command?? if u exclude the sleep command you get funny output..
////
main()
{
fork();
fork();
printf("parent pid %d\n", getppid());
sleep(3);
}
//////
the output that i get with the sleep command is
parent pid 3947
parent pid 3946
parent pid 3946
parent pid 2699
the output that i get without the sleep command is..
parent pid 3947
parent pid 3946
[XXX @localhost]parent pid 1
parent pid 1 (with the curser blinking continuously at this point)
With zombie processes you want to handle them with a waitpid signal handler on the SIGCHLD signal. Which may sound like a lot of gobbledegook however it should give you sufficient information to do an effective goggle and make some sense of it .
As for your code the standard approach is to look at the return from fork. If it is zero then you are in the parent process, if it is non zero then you are in the child process and the value returned is the pid of the parent. The reason you have four values displayed is there is first of all the parent, then the parent creates a child (1st fork) then the 1st child and the parent create a child each (2nd fork), giving you a total of four children. If you check that you are in the parent process before forking then you will create a total of two children and one parent.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.