Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are forking a child-process, but what does the parent process do after the call to <code>fork()?</code> It seems you are wanting to recursively fork processes, but in order for that to work properly, you will have to-do the following:</p> <p>1) Check to see if there are any sub-directories in the current directory ... if there aren't any, then <code>exit()</code>, otherwise read all the sub-directories in the current directory.</p> <p>2) For each sub-directory fork a process. If the fork is the child (i.e., <code>pid == 0</code>), then make a call to <code>execvp()</code>.</p> <p>3) If <code>pid != 0</code>, then you're in the parent process. Rather than trying to sleep for some period of time, make a call to <code>wait()</code>, and keep on repeating the call to <code>wait()</code> until there are no child processes left.</p> <p>4) Once there are no child-processes left (i.e., <code>wait()</code> returns an error status such that <code>errno == ECHILD</code>), then you can make a call to <code>exit()</code> in the parent process.</p> <p>So if you follow those 4 steps, you should not incurr any infinite loops. Every child process will at some point exit once they reach a directory with no more sub-directories, and every parent will wait for it's children before exiting so you won't end up with any orphaned processes. If you do end up with an infinite loop, then it's because a child process is not exiting, which would then point to the logic used to detect if there are any sub-directories in the current directory, or you're not properly detecting that there are no longer any child left to wait for in a parent process.</p> <p>Hope this helps,</p> <p>Jason</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload