Using cd command with fork in c
<p>Is it possible to change around directories using the fork command? Without going too much into my code I have the following:</p>

<pre><code>childpid = fork();

if (childpid &gt;= 0)
{
    if (childpid == 0)
    {   
        ret = execvp(argv[0],argv);
        exit(ret);    
    } else {

          waitpid(childpid,&amp;status,0);
          ret = WEXITSTATUS(status);
    }
}
</code></pre>

<p>The above works fine when I'm entering basic command like <code>ls</code>, <code>pwd</code>, etc.. Is it possible to implement a way to use the cd function? I can type the command <code>cd ..</code> but it doesn't do anything.</p>

<p>For example if my program is in <code>/Users/username/Desktop/</code> I would like to use commands such as <code>cd ..</code> to go into <code>/Users/username/</code> or be able to go straight into <code>/Users</code> </p>

<p>I've seen some stuff about <code>chdir</code> but I'm not sure exactly how it works/how to use it.</p>