进程

Friday, September 6, 2019

进程 API

fork()系统调用

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

int main(int argc, char *argv[])
{
    printf("hello world (pid:%d)\n", (int) getpid());
    int rc = fork();
    if (rc < 0) {
        fprintf(stderr, "fork failed\n");
        exit(1);
    } else if (rc == 0) {
      // child(新的子进程)
      printf("hello, I am a child(pid:%d)\n",(int)getpid());
    } else {
      prinftf("hello, I am parent of %d (pid:%d)\n", rc, (int)getpid());
    }
    return 0
}
OS

受限制直接执行

进程