/* * Copyright (c) 1996 Gunther Schadow. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include int termh(Signal &s) { cout << "Help! I (" << getpid() << ") am shot by signal " << s.signal() << "! Someone wants to kill me!" << endl; if(getpid() % 3) { cout << "Puh, I (" << getpid() << ") was lucky this time ..." << endl; Timer::sleep(0,100000); cout << "... but, I (" << getpid() << ") should better leave this place!" << endl; Timer::sleep(0,700000); exit(0); } else { cout << "Ahhhhhhhhhhhhhh...." << endl; _exit(1); } } main() { Signal sigint(SIGINT, NULL, 0, Signal::f_disable); atSignal(sigint) { cout << "STOPPED (" << getpid() << ")!" << endl; return 1; } Proc pc(ProcInfo::now); if(pc.child()) { Signal sigterm(SIGTERM, termh); cout << "I am the child: " << getpid() << endl; pause(); } else { cout << "I am the parent: " << getpid() << ", and this is my child: " << pc.pid() << endl; Timer::sleep(0,200000); cout << "Now, I (" << getpid() << ") gonna kill my child, hehe!" << endl; Timer::sleep(0,100000); kill(pc.pid(), SIGTERM); Timer::sleep(0,500000); if(! pc.running()) { cout << "Well, the job is done for me (" << getpid() << "), bye, see ya!" << endl; } else { cout << "Grrrr! I (" << getpid() << ") wasn't able to kill it!" << endl; } return 0; } }