Catch the kill command?

Posted on 2005-03-14
Medium Priority
Last Modified: 2010-04-22
If my process is running with a PID of 1000, is there a way to catch in my code when someone at the terminal types in:  kill 1000 ?

I want to know this so I can free up used resources, and close up log files.
Question by:lwinkenb
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Expert Comment

ID: 13538059
It's easy to cach a signal:

void sighandler(int number)
    printf ("Process is killed!\n");

int main()
    signal(SIGKILL, sighandler);
    /* rest of your program */

But what is exactly that you want? Do you mean that program with pid 1000 is already running and you want to protect it from killing? I don't suppose its possible...

Author Comment

ID: 13538210
That didn't work.  I tried the above code, and it just said "Terminated" when I killed it.  It didnt say "Process is killed!".

>> Do you mean that program with pid 1000 is already running and you want to protect it from killing?
The program with pid of 1000 is the small program I am writing here.  This is the one that is catching the signal.

Accepted Solution

Robson earned 1000 total points
ID: 13538313

signal(SIGTERM, sighandler);

SIGKILL is actualluy unblockable and you send it with kill -9



Author Comment

ID: 13538523
Thanks =)

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question