-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathhello.c
37 lines (29 loc) · 811 Bytes
/
hello.c
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
36
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <errno.h>
//int make_happy(int happy)
//{
// printf("print Happy! %d\n", happy);
// return 1;
//}
int main(int argc, char *argv[])
{
pid_t pid;
if ((pid = fork()) < 0) {
fprintf(stderr, "fork error\n");
} else if (pid == 0) { /* specify pathname, specify environment */
execl( "/bin/ls", "/bin/ls", NULL);
printf("I’m Child PID = %d, Parent PID =%d\n", getpid(), getppid());
}
// if (waitpid(pid, NULL, 0) < 0)
// fprintf(stderr, "wait error\n");
if ((pid = fork()) < 0) {
fprintf(stderr, "fork error\n");
} else if (pid == 0) { /* specify filename, inherit environment */
// system("/bin/ls -a");
printf("I’m Child PID = %d, Parent PID =%d\n", getpid(), getppid());
}
exit(0);
}