Debian Codegraph @

yo/concrete/examples/monitor/monitor.cc

raw
1 #include "monitor.ih"
2
3 //KILL
4 void Monitor::killChild(MapIntChild::value_type it)
5 {
6 if (kill(it.second->pid(), SIGTERM))
7 cerr << "Couldn't kill process " << it.second->pid() << '\n';
8
9 // reap defunct child process
10 int status = 0;
11 while( waitpid( it.second->pid(), &status, WNOHANG) > -1)
12 ;
13 }
14 //=
15 //EXIT
16 void Monitor::exiting(int value, string const &msg)
17 {
18 for_each(d_child.begin(), d_child.end(), killChild);
19 if (msg.length())
20 cerr << msg << '\n';
21 throw value;
22 }
23 //=
24 //INIT
25 void (Monitor::*Monitor::s_handler[sizeofCommands])(int, string const &);
26
27 int Monitor::initialize()
28 {
29 s_handler[UNKNOWN] = &Monitor::unknown;
30 s_handler[START] = &Monitor::createNewChild;
31 s_handler[EXIT] = &Monitor::exiting;
32 s_handler[STOP] = &Monitor::stopChild;
33 s_handler[TEXT] = &Monitor::sendChild;
34 return 0;
35 }
36 //=