wait(&status) always return 0
<p>I'm try to get exit status of child process but always gets 0.
what I'm doing wrong, is this not the way?</p>

<p>here is my code, tokens = an commands array.
thanks</p>

<pre><code>int execute(char** tokens)
{
    pid_t pid;
    int status;

    pid = fork();

    if (pid == -1)
    {
        fprintf(stderr,"ERROR: forking child process failed\n");    
        return -1;
    }

    // Child process
    if (pid == 0)
    {
        // Command was failed
        if (execvp(*tokens, tokens) == -1)
        {
            fprintf(stderr, "%s:command not found\n", *tokens);
            return 255;
        }
    }
    else
    {
        pid = wait(&amp;status);
        status = WEXITSTATUS(status);   
    }

    return status;

}
</code></pre>

<p>always:
status = 0.</p>

<p>what I need to change?</p>