赞
踩
- #include <sys/types.h>
- #include <unistd.h>
-
- pid_t getpid(void);
- pid_t getppid(void);
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdio.h>
-
- int main()
- {
- printf("pid = %x, ppid = %x\n", getpid(), getppid());
- return 0;
- }
pid = 4761, ppid = 2570
- #include <unistd.h>
-
- pid_t fork(void);
- #include <stdio.h>
- #include <unistd.h>
-
- int main()
- {
- int pid;
- pid = fork();
- if (pid == 0)
- puts("child");
- else
- puts("parent");
- return 0;
- }
- parent
- child
- #include <stdio.h>
- #include <unistd.h>
-
- int main()
- {
- int pid;
- pid = fork();
- if (pid == 0)
- printf("child: my = %d, parent = %d\n", getpid(), getppid());
- else
- printf("parent: my = %d, child = %d\n", getpid(), pid);
- return 0;
- }
- parent: my = 6988, child = 6989
- child: my = 6989, parent = 6988
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。