Jump to content
  • Advertisement
Sign in to follow this  

Linux: send signal to stop process

This topic is 2119 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

That is entirely dependent on how your program works and where it processes that input. Some options (assuming C):
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)
It also depends on what you mean by "graceful," as some will argue that exit(0); is not graceful because it doesn't allow you to do any clean up, whereas others will argue it is graceful because the OS will, in some way, do any cleanup you failed to do. Edited by Cornstalks

Share this post

Link to post
Share on other sites

[quote name='Cornstalks' timestamp='1356775436' post='5015383']
kill(getpid(), SIGTERM);

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.

Share this post

Link to post
Share on other sites
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


kill -TERM $pid # sends the terminate signal (same as control-C)

where $pid is the process ID of your process.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!