How to detect SIGTERM,SIGKILL signal in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to detect SIGTERM,SIGKILL signal in UNIX
# 1  
Old 03-08-2010
How to detect SIGTERM,SIGKILL signal in UNIX

Dear All

We have JBOSS server running on Linux we need to track Graceful Shutdown(SIGTERM) and Forceful Shutdown(SIGKILL) timestamp and write it into one file, I am new to UNIX Signal processing if is it possible how to detect it?

We generally do
$kill PID For Graceful Shutdown(SIGTERM)
$kill -9 PID For Forceful Shutdown(SIGKILL)

Thanks in advance.Is is possible using Shell Script or C or JAVA if yes please suggest me.

We or else someone is killing the process id of java process associated with JBOSS.
i.e we get Java process ID from `ps -ef|grep java` command output and someone is killing this PID using kill command. I have to track at what timestamp java process is killed and associated SIGNAL information i.e either SIGTERM , SIGKILL or it is for system's abnormal shutdown

Is it possible to track this information ? if yes Please help me it's an urgent.........

Regards
Mnmonu

Last edited by mnmonu; 03-09-2010 at 03:35 AM..
# 2  
Old 03-08-2010
What are you killing with those commands?

Processes of shell scripts, compiled binaries?
# 3  
Old 03-08-2010
you cannot intercept kill -9 at all.
# 4  
Old 03-08-2010
You can use 'trap' within the parent script to capture signals and perform commands before exiting.
Code:
$ trap -l
 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL
 5) SIGTRAP      6) SIGABRT      7) SIGEMT       8) SIGFPE
 9) SIGKILL     10) SIGBUS      11) SIGSEGV     12) SIGSYS
13) SIGPIPE     14) SIGALRM     15) SIGTERM     16) SIGURG
17) SIGSTOP     18) SIGTSTP     19) SIGCONT     20) SIGCHLD
21) SIGTTIN     22) SIGTTOU     23) SIGIO       24) SIGXCPU
25) SIGXFSZ     26) SIGVTALRM   27) SIGPROF     28) SIGWINCH
29) SIGLOST     30) SIGUSR1     31) SIGUSR2     32) SIGRTMAX

An example:
Code:
stty echo # turn echo off prior to capturing a password
trap 'stty echo;exit' INT  # if the user does a ctrl+c to exit the password prompt the trap will turn the echo back ON.

[/code]
# 5  
Old 03-08-2010
Do not trap signal 9.
BTW it is rarely ever necessary or advisible to issue "kill -9" unless you are in severe difficulties when shutting a system down.
Suggest you approach the software authors about the correct way to shut down the application.
# 6  
Old 03-09-2010
We or else someone is killing the process id of java process associated to JBOSS.
i.e we get Java process ID from `ps -ef|grep java` command output and someone is killing this PID using kill command. I have to track at what timestamp java process is killed and associated SIGNAL i.e either SIGTERM or SIGKILL

Is it possible to track this information ?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to detect files transmission at UNIX server ?

Dear Expert Users, I know that Unix utility ( fuser ) is used to detect "transmission" of files from Source system to "current Linux Server". I have scheduled this Unix script to work every 30th minutes of the hour and whenever files transmission starts at that very moment. And, the file... (4 Replies)
Discussion started by: schandrakar1
4 Replies

2. Programming

UNIX signal problem

Hi all, Sorry about the title,at first i decided to ask a problem about the signal mechanism,however,i'm now figured it out.Sorry to forget modify the title:wall:.I had a small problem that if i use the code which is commented,the code would get a segment fault,while the above code NOT.what's... (4 Replies)
Discussion started by: homeboy
4 Replies

3. Shell Programming and Scripting

SIGSTOP and SIGKILL

Which is sent to a terminal when it closes? SIGKILL? Reason I ask is I have a script I want to run in the background, but want it to run even if the terminal window is closed. Or, I'd like it to background itself if the terminal is closed but not if its running in an open window. I will learn how... (5 Replies)
Discussion started by: DC Slick
5 Replies

4. Solaris

Signal Processing in unix

I've read the man page of singal(3) but I still can't quite understand what is the difference between SIGINT, SIGALRM and SIGTERM. Can someone tell me what is the behavioral difference among these 3 signals in kill command? Thanks! (2 Replies)
Discussion started by: joe228
2 Replies

5. Programming

Reliable management of signal SIGPIPE and SIGTERM

I' m note very expert in the reliable manage of signal... but in my server I must manage SIGPIPE for the socket and SIGTERM... I've wrote this but there is something wrong... Can someone explain me with some example the reliable management of signal?? This is what I've wrote in the server ... (2 Replies)
Discussion started by: italian_boy
2 Replies

6. Solaris

SIGQUIT and SIGKILL message

Dear All, I have machine with SunOS 5.10 Generic_138888-01 sun4v sparc SUNW,SPARC-Enterprise-T5120. Yesterday there is something at dmesg command : May 25 18:09:02 cacao_launcher: Timeout occured on heartbeat channel, cleanup engaged May 25 18:09:07 cacao_launcher: watchdog : warning,... (0 Replies)
Discussion started by: mbah_jiman
0 Replies

7. Programming

How to implement SIGKILL and SIGTERM and print a message?

Hello, I am running a webserver that uses sockets, forks, and children. The parent process listens for connections and the child processes the information. I am trying to figure out why the code I have below SIGTERM, and SIGKILL never fire. I was messing around with the printfs and doesnt... (11 Replies)
Discussion started by: norelco55
11 Replies

8. UNIX for Advanced & Expert Users

Help required regarding Unix Signal

It is required to trap the signal send to a daemon process before rebooting a unix server. Suppose a script abc.ksh is running in the server as daemon. Before rebooting the server, the unix admin kills all the daemon processes. It is not known to me how admin kills the processes; I mean by which... (9 Replies)
Discussion started by: k_bijitesh
9 Replies

9. Shell Programming and Scripting

Why SIGKILL will occur?

Hi Gurus, I am executing my Datastage jobs on UNIX operating System. While running the jobs i am getting the following error: main_program: Unexpected termination by Unix signal 9(SIGKILL) Can any one please let me know what are the possible situations where this SIGKILL will arrise? ... (9 Replies)
Discussion started by: choppas
9 Replies
Login or Register to Ask a Question