Killing child process
Hi,
i am currently working on the Diner Philosophers problem. I have this code : Code:
while(ctr < 5) |
As far as I know, there are two ways to prevent the child process from becoming a zombie process.
1. Call wait() from the parent process. 2. After the first fork(), fork() again and kill the child process immediately thus handing the grand-child process to the init process. I am not sure whether you should do a wait() in the parent process in this case. So please do experiment yourself. Search for "kill zombie process" may help you understand why those child processes exist. |
Moved: Seems more suitable in the Programming forum.
|
sleep() takes its time in seconds, and rand returns a number between 0 and RAND_MAX. On my system, RAND_MAX is over 200 million, so your program would sleep, on average, around 3 years at the first "THINKING" comment. That sounds wrong.
To kill a process, see the kill() syscall's man page. |
All times are GMT -5. The time now is 06:19 PM. |