#include <stdlib.h> #include <stdio.h> #include <unistd.h> int main() { pid_t pid; pid = fork(); switch(pid) { case 0: printf("child process is running, curpid is %d, parentpid is %d\n", pid, getpid()); break; case -1: perror("process creation failed\n"); break; default: printf("parent process is running, cur pid is %d, parentpid is %d\n", pid, getpid()); break; } exit(0); }
第一次编译出了个问题:undefined reference to main。在这之前我装了个g++,其他的没变,这个问题后来自己就好了,我也不知道为什么,有知道的帮忙解答下,先谢过了。
http://www.oschina.net/code/snippet_171680_6746
转载于:https://my.oschina.net/u/212651/blog/38450
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/110491.html原文链接:https://javaforall.net