#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <err.h>

int
main(int argc, char *argv[])
{
    int istack = 222;

    switch (vfork()) {
    case -1:
        err(EXIT_FAILURE, "vfork");

    case 0:             /* child executes first, in parent's memory space */
        sleep(3);       /* Even if we sleep for a while
                           parent still is not scheduled */
        write(STDOUT_FILENO, "child executing\n", 16);
        istack *= 3;    /* this change will be seen by parent */
        _exit(EXIT_SUCCESS);

    default:            /* parent is blocked until child exits */
        write(STDOUT_FILENO, "parent executing\n", 17);
        printf("istack=%d\n", istack);
        exit(EXIT_SUCCESS);
    }
    exit(EXIT_SUCCESS);
}
