I want to write a ‘zombie creator’ and ‘zombie terminator’. Main point is that I want to create zombies in one part and terminate them in other part of code. I’m using C.
Example:
create_zombie(); //let's say it's a spawn, using fork etc.
/* a houndred lines below */
kill_zombie(PID); // PID is determinated by user, I want to leave him the choice
I know how to do this using fork(), if .. else, but that’s not the point. I’m looking for some kind of remote control. Is that possible? Sleeping him for a long time could be a solution?
I’m assuming Linux, but the process should be similar on other operating systems. You want to look into the
kill()function declared typically declared in thesignal.hheader file. This will allow you to send a signal to a specific PID from your zombie killer. The easiest approach would be to send your zombie process a kill signal (SIGKILL).SIGKILLcannot be caught or ignored, and immediately kill a process dead.If you need to do some cleanup in your zombie process, you can create a signal handler with the
signal()function. This will allow you to specify a function to call when a process receives a signal. This function would implement your cleanup code and thenexit().On linux, your shell should have a kill command that mimics the functionality of
kill(). The syntax is typicallykill -s 9 PID. This will send a SIGKILL (signal number 9) to the process PID.I hope this answer nudges you in the proper direction.