36 lines
681 B
C
36 lines
681 B
C
// Write a program that creates a zombie, and then call system() from stdlib.h
|
|
// (for executing a command from within a program) to execute the ps(1) command
|
|
// to verify that the process is a zombie.
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <signal.h>
|
|
|
|
void create_zombie() {
|
|
int pid = fork();
|
|
|
|
if (pid == 0) {
|
|
sleep(100000);
|
|
} else {
|
|
_exit(0);
|
|
}
|
|
}
|
|
|
|
void get_ps(int pid) {
|
|
char spid[1000];
|
|
sprintf(spid, "ps aux | awk '$2 == %d { print }'", pid);
|
|
system(spid);
|
|
}
|
|
|
|
|
|
int main(void) {
|
|
int pid = fork();
|
|
|
|
if (pid == 0) {
|
|
create_zombie();
|
|
} else {
|
|
get_ps(pid);
|
|
}
|
|
|
|
return -1;
|
|
}
|