File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 1
1
2
2
# Add all targets here
3
- BINARIES =simple_fork child_status
3
+ BINARIES =simple_fork child_status child_exec
4
4
5
5
all : $(BINARIES )
6
6
@@ -17,6 +17,12 @@ child_status.o: child_status.c
17
17
gcc child_status.c -c
18
18
19
19
20
+ child_exec : child_exec.o
21
+ gcc -o child_exec child_exec.o
22
+ child_exec.o : child_exec.c
23
+ gcc child_exec.c -c
24
+
25
+
20
26
.PHONY : clean
21
27
clean :
22
28
rm -f * .o $(BINARIES )
Original file line number Diff line number Diff line change
1
+ #include <sys/types.h>
2
+ #include <sys/wait.h>
3
+ #include <stdio.h>
4
+ #include <stdlib.h>
5
+ #include <unistd.h>
6
+
7
+ int main (int argc , char * argv [])
8
+ {
9
+ pid_t pid ;
10
+ pid = fork ();
11
+
12
+ if (pid < 0 ) {
13
+ /* there was an error */
14
+ fprintf (stderr , "%d: Fork failed\n" , getpid ());
15
+ } else if (pid == 0 ) {
16
+ /* child gets a pid of zero */
17
+ printf ("Child:\n" );
18
+ execl ("/bin/ls" , "ls" , NULL );
19
+ printf ("We'll never reach here\n" );
20
+ } else {
21
+ /* inside parent */
22
+ wait (NULL );
23
+ printf ("\nChild complete\n" );
24
+ }
25
+
26
+ return 0 ;
27
+ }
You can’t perform that action at this time.
0 commit comments