lwinkenb
asked on
Catch the kill command?
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.
I want to know this so I can free up used resources, and close up log files.
ASKER
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.
>> 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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks =)
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...