How can I send my process to stop gracefully?
I want to be able to call it in the console:
myProcess stop
How can I send my process to stop gracefully?
I want to be able to call it in the console:
myProcess stop
exit(0);
kill(getpid(), SIGTERM); // or, to send it to the group: kill(-getpid(), SIGTERM);
kill(getpid(), SIGKILL); // or, to send it to the group: kill(-getpid(), SIGKILL);
return 0; // from the main() function
throw std::exception(); // assuming C++, and that you catch (std::exception) somewhere appropriate (like the end of your main() function)
[quote name='Cornstalks' timestamp='1356775436' post='5015383']
kill(getpid(), SIGTERM);
[/quote]
I'd suggest also to install a handler for this signal to perform any manual cleanups like finishing network sessions properly, dump config files etc.
How can I send my process to stop gracefully?
I want to be able to call it in the console:
I'm not sure what you mean by "call it in the console" means, but the shell command you would use to stop a process is the kill command.
kill -HUP $pid # sends the hangup signal
or
kill -TERM $pid # sends the terminate signal (same as control-C)
where $pid is the process ID of your process.