|
发表于 2004-11-3 13:04:45
|
显示全部楼层
其他的自己作吧
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- int main(int argc, char *argv[])
- {
- pid_t pid;
- FILE fp;
-
- printf("1 My own pid = %d\n My ppid = %d\n",
- getpid(),getppid());
- if( (pid = fork()) < 0) {
- printf("Error!!!\n");
- exit(0);
- } if (pid == 0) {
- printf("2 MY child process id = %d\n MY parent procss id = %d\n",
- getpid(), getppid());
- sleep (5);
- printf("after 5s\n");
- printf("2 MY child process id = %d\n MY parent procss id = %d\n",
- getpid(), getppid());
- } else {
- printf("3 The child process id is(I am parent) = %d\n", pid);
- sleep(1);
- printf("3 I will go, if u miss me ,just call me:)\n");
- }
- return 0;
- }
复制代码 |
|