File: vfork.c

package info (click to toggle)
chibicc 1.0.23.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,832 kB
  • sloc: ansic: 62,911; sh: 275; makefile: 92
file content (27 lines) | stat: -rw-r--r-- 602 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "test.h"
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h> 

int main(void) {
    pid_t pid = 0;
    int errpipe = 0;   // simulate parent stack variable for error reporting

    pid = vfork();
    if (pid < 0) {
        perror("vfork");
        return 1;
    }

    if (pid == 0) {  // child
    //     // safe write to parent stack variable
         errpipe = 123;
         return 0;   // child exits safely
     }

    // parent reads updated value
    printf("errpipe = %d\n", errpipe);
    ASSERT(123, errpipe);
    printf("OK\n");
    return 0;
}