• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

My Fork() don't Work!

Asparagus

Senior member
Newbie to Forking here...

I need to create a simple program that runs on Linux (Fedora Core 2, to be exact) that has a parent process that spawns 9 child processes. The child processes need to hang around for about 10 seconds or so (long enough to see all of the processes running when you type "ps" command). Then, the child processes need to die and then finally the parent. (So tragic!)

I thought that putting the fork calls inside of a FOR loop would do it for me, but it doesn't. A whole lot more than 9 child processes are being created. The code is below...what am I doing wrong???

Thanks in advance...
 
You need to put a test around your forking loop (sorry - it just had to be said that way 😛 ) to check whether the current process is the parent or not. As it is, your parent spawns 9 processes, and each of these nine processes spawns 9 more ... ad-infiniteum. You've just built a nice fork-bomb.
 
Back
Top