File tree 4 files changed +59
-0
lines changed
4 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ course in Bits, Goa.
10
10
- Fork this shit: examples of forking
11
11
- Kernel Modules: kernel modules
12
12
- Process communication: process communication
13
+ - Zombie: make a zombie
13
14
14
15
## Author
15
16
Utkarsh Maheshwari
Original file line number Diff line number Diff line change
1
+
2
+ # Add all targets here
3
+ BINARIES =zombie
4
+
5
+ all : $(BINARIES )
6
+
7
+
8
+ zombie : zombie.o
9
+ gcc -o zombie zombie.o
10
+ zombie.o : zombie.c
11
+ gcc zombie.c -c
12
+
13
+
14
+ .PHONY : clean
15
+ clean :
16
+ rm -f * .o $(BINARIES )
Original file line number Diff line number Diff line change
1
+ ## Zombie
2
+ Makes a zombie process
3
+
4
+ #### Compile:
5
+ - all:
6
+ ``` bash
7
+ make all
8
+ ```
9
+
10
+ - selectively, 'package':
11
+ ``` bash
12
+ make package
13
+ ```
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 <unistd.h>
5
+
6
+ int main (int argc , char * argv [])
7
+ {
8
+ pid_t pid , me ;
9
+ pid = fork ();
10
+
11
+ if (pid == 0 ) {
12
+ me = getpid ();
13
+ printf ("%d: I love eating brains\n" , me );
14
+ printf ("%d: I am a zombie!\n" , me );
15
+ } else {
16
+ me = getpid ();
17
+
18
+ printf ("%d: Killing my child\n" , me );
19
+ printf ("%d: Damn! He's a zombie now!\n" , me );
20
+
21
+ /* sleep so that my child becomes a zombie */
22
+ sleep (20 );
23
+ wait (NULL );
24
+
25
+ printf ("%d: Not anymore\n" , me );
26
+ }
27
+
28
+ return 0 ;
29
+ }
You can’t perform that action at this time.
0 commit comments