#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
Include dependency graph for timeout.c:

Go to the source code of this file.
Functions | |
| void | family_assassination (int ignored) |
| When triggered, kills the process at _pid. | |
| int | main (int argc, char *argv[]) |
| Main function: set up the alarm and run the child process until it quits or the alarm fires. | |
Variables | |
| int | _pid = -1 |
| global for the money-shot: the pid that is killed when the alarm goes off | |
This file was written for the regression-testing of the nagios/ldap and the fsc-fs work which I was doing on my own inspired by the needs of a company I worked for in 2007. The function fork/execs a child process, and sets an alarm. If the child quits, all is fine; if the alarm goes off, it kills the child in a relatively impolite manner: SIGTERM, wait 1 sec, SIGKILL. There's a bit of tongue-in-cheek here, but that's the basics.
family_assassination() is the function tied to the SIGALRM; the wait for a normal termination is done with a wait() or pause().
This file is permitted use as GPL2 or Attribution + ShareAlike (by-sa) Creative-Commons. Whichever works for you.
Definition in file timeout.c.
| void family_assassination | ( | int | ignored | ) |
| int main | ( | int | argc, | |
| char * | argv[] | |||
| ) |
Main function: set up the alarm and run the child process until it quits or the alarm fires.
This function reads the parameters, set up a SIGALRM to call family_assassination() (kill your child, get it? dark humour, I'm sorry), then lauunch the child process an wait for it to finish. If the alarm goes off before the child finishes, this program kills the child and itself like a gruesome story in the newspaper; if the child finishes, then we terminate normally, which is nearly as gruesome (again, sorry).
0 if there are no problems and child completed normally
Definition at line 52 of file timeout.c.
References _pid, family_assassination(), and opt.
Here is the call graph for this function:

| int _pid = -1 |
global for the money-shot: the pid that is killed when the alarm goes off
Definition at line 24 of file timeout.c.
Referenced by family_assassination(), and main().
1.4.7