Discuss Fork in c in the C Programming forum on Dev Shed. Fork in c C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
Time spent in forums: 2 Months 2 Weeks 4 Days 2 h 24 m 53 sec
Reputation Power: 3716
Read the manual page for fork, it tells you how to use it properly.
On success, the PID of the child process is returned in the parent's thread of execution, and a 0 is returned in the child's thread of execution. On failure, a -1 will be returned in the parent's context, no child process will be created, and errno will be set appropriately.
So you need to use a if statement to test the return value of fork. If the value is 0, then you need to branch off to the child code you want to execute. If the return value is non-zero, then you need to branch off in the parent side of the code and save the return value (which is the PID of the child that was just spawned).
//Save pid of child
//do child code;
Location: Central New York. Texan via Arizona, out of his element!
Time spent in forums: 4 Weeks 20 h 13 m 16 sec
Warnings Level: 20
Number of bans: 3
Reputation Power: 3268
Sheet fahr. First you say you're listening, then you mumble on like you're deaf. I could just crap and fall back in it.
Functionality rules and clarity matters; if you can work a little elegance in there, you're stylin'.
If you can't spell "u", "ur", and "ne1", why would I hire you? 300 baud modem? Forget I mentioned it. DaWei on PointersPolitically Incorrect.