erezul
erezul

Reputation: 527

How can I find who or which process sent signals to my process on Solaris

I have JBoss running on Sun Java 1.5. From time to time, it unexpectedly shuts down (in orderly fashion). I suspect some other process is sending it kill or CTRL+C signals.

Is there a way on Unix/Solaris to trace who sent the signal?

Upvotes: 2

Views: 4961

Answers (2)

jlliagre
jlliagre

Reputation: 30813

On Solaris, you can use a simple dtrace script to find who is killing your process (assuming its name is java, adjust it otherwise):

dtrace -qn '
proc:::signal-send
/ args[1]->pr_fname == "java" /
{
        printf("Process %d (%s by UID %d) sending signal %d to java (pid=%d)\n",
        pid,execname,uid,arg1,args[1]->pr_pid);
}'

Upvotes: 7

Ulrich Dangel
Ulrich Dangel

Reputation: 4625

You can use sigaction to determine the source of the signal. pid may be zero as the signal was send from the kernel or via some user interaction (pressing ctrl+c)

#include <signal.h>
#include <string.h>
#include <stdio.h>

static void signal_handler(int sig, siginfo_t *info, void *data) {

    printf ("signal: [%d], pid: [%d], uid: [%d]\n", sig,
            info->si_pid,
            info->si_uid );
}

int main(int argc, char *argv[]) {

    struct sigaction sa;
    memset ( &sa, '\0', sizeof ( struct sigaction ) );

    sa.sa_sigaction = &signal_handler;
    sa.sa_flags |= SA_SIGINFO;

    sigemptyset ( &sa.sa_mask );

    sigaction(SIGINT, &sa, NULL);
    sigaction(SIGTERM, &sa, NULL);
    sigaction(SIGQUIT, &sa, NULL);

    while ( 1 ) {
        sleep (1);
    }

    return 0;
}

Upvotes: 1

Related Questions