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

What are you killing with those commands?

Processes of shell scripts, compiled binaries?

you cannot intercept kill -9 at all.

You can use 'trap' within the parent script to capture signals and perform commands before exiting.

$ 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:

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]

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.

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 ?