I have a开发者_如何学JAVA c program with say n number of for loops. How many processes and child processes will be running for this program and how?
A for loop does not fork a new process. N number of for loop should run in a single process.
If you doesn't make fork you will have only one process. So show your code if you use fork.
The C language itself does not support multi-processed program. You should depend on API's provided by your OS to implement a multi-processed version. You can use fork function under Linux and CreateProcess in Windows environment and corresponding platform dependent API's can give you details on how to use these functions. Good luck!
edit : Just for
loops won't make any new processes, and the for loops will be executed in one process only. If you want to make a new process in Linux use fork()
.
If I remember well,
Using N for loops with each loop iterating M times will make something like M^N Processes, which will in turn make another sea of M^N processes since fork() creates identical processes etc... etc... . The system might turn to be very slow, and if the MAX_PROCESS is exceeded, fork() will not make any new processes.
The First process will create M^N Child Processes. Those children each one of them will also create M^N Child process etc... etc..
what you trying to achieve ?
精彩评论