Exec (cd and ls) and Fork call C
<p>I'm trying make a simple example with the exec() and fork(). But I have a little problem and I did't understand how fix it. </p>

<p>The code does 3 forks, and in each child it calls one exec. The first system call is "who", after "cd", and "ls -ls". My problem is: after made "cd", the "ls" call doesn't show the files in the current directory. So, if I have 'dir1/dir2', I do "cd", but when I do "ls" the program shows the files in 'dir/dir2'. </p>

<p>It's possible one child access the changes made by another child?  </p>

<pre class="lang-c prettyprint-override"><code>while (cont_arg &lt; 3) {
        pid_t pid = fork();
        if (pid == -1) {
            perror("fork failed");
            exit(EXIT_FAILURE);
        } else if (pid == 0) {
            printf("\n---: child process ID -&gt; %d.\n", getpid());
            printf("command --- &gt; %s\n", command[cont_arg]);
            execlp(command[cont_arg], command[cont_arg], arg[cont_arg], NULL);
            _exit(EXIT_SUCCESS);
        } else {
            wait(&amp;status);
        }
        cont_arg++;
    }
</code></pre>