zombie.cpp

URL: https://mirkwood.cs.edinboro.edu/~bennett/class/cmsc4000/spring2026/notes/ch3/code/zombie.cpp
 
#include <unistd.h>
#include <iostream>


using namespace std;

int main() {
    cout << endl << endl;

    pid_t forkValue {fork()};

    switch(forkValue) {
       case 0:
           cout << getpid() << " is the child and it will exit" << endl;
           return 0;
       default:
           sleep(1);

           cout << endl;
           string cmd = "head -4 /proc/"+to_string(forkValue) + "/status";
           cout << "Running " << cmd << endl;
           system(cmd.c_str());
           cout << endl;

           cmd = "ps -ef | grep " + to_string(forkValue);
           cout << "Running " << cmd << endl;
           system(cmd.c_str());

           cout << "Enter anything to continue" << endl;
           string junk;
           getline(cin, junk);
           return 0;

    }
}