下面是代码
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 28 29 30 31 32 33 34 35 |
#include <unistd.h> #include <cstdio> #include <cstdlib> #include <cstring> int main(int /*argc*/, char** argv) { pid_t pid = fork(); switch (pid) { case -1: { perror("fork"); exit(EXIT_FAILURE); } break; case 0: { printf("I'm chilid, pid: %d\n", getpid()); const char* p = "haha:child"; strcpy(argv[0], p); } break; default: { printf("I'm parent, pid: %d\n", getpid()); const char* p = "haha:parent"; strcpy(argv[0], p); } break; } while(1) usleep(100000); return 0; } |
编译后查看,已经变了.如开篇所示效果图
发表评论
要发表评论,您必须先登录。