[Help]Fork Command
Hello,
I have a university assignment in which we are asked to use the fork() programming construct to create some number of processes, specified on the command line - for example - the command ./FORK1.exe 6 should create 6 new simultaneously - executing processes as quickly as possible. Each process except the original should then print out its own process ID using getpid() which returns the current process ID when it is called. After printing out the process ID, each process should wait for two (2) seconds by calling sleep(2) and then exiting: exit().
The main - parent process should wait three (3) seconds before exiting. Use atoi() to convert the input from command line from ascii to integer.
I am using fork() command in while loop for the creation of child processes. The problem is that each fork() command further creates more child processes. How can I prevent this to happen using while loop or any other solution?
I hope I was clear enough in explaining the problem. Please let me know if you need any clarification.
Help will be much appreciated.
Thanks,
ANK