Set time limit to a child process
<p>I'm creating a shell and have a problem when creating my own <code>ulimit</code> function : I want to limit the time of a process, and I use <code>setrlimit</code> for it. But it seems that when I call <code>execvp</code> then, the time limit is kind of erased.</p>

<p>In this example code, when I let the <code>while(1)</code>, the child process receives a <code>SIGXCPU</code> and is killed after 3 seconds. But when I do <code>execvp(...)</code> instead, it's never killed.</p>

<pre><code>#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdint.h&gt;
#include &lt;unistd.h&gt;
#include &lt;sys/wait.h&gt;
#include &lt;sys/time.h&gt;
#include &lt;sys/resource.h&gt;

int main(void) {
    struct rlimit t = {3, 8};

    uint32_t child_pid = fork();

    // father
    if (child_pid != 0) {
        waitpid(child_pid, NULL, 0);

    // child
    } else {
        setrlimit(RLIMIT_CPU, &amp;t);
        char* s[3];
        s[0] = "sleep";
        s[1] = "1000";
        s[2] = NULL;

        /* while(1); */
        execvp(*s, s);
    }
}
</code></pre>

<p>If I'm right and the time limit I set with <code>setrlimit</code> is erased, how to do it then ?</p>

<p>Thanks for help.</p>