Getting status of a signal in process?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Getting status of a signal in process?
# 1  
Old 01-18-2008
Error Getting status of a signal in process?

Hi all,
How can a process be aware of the signals it handles. I looked at available signal API, but couldn't find any help.

If a process defines it own handler for a signal, the default handler for that signal becomes overridden.

I am interested in getting to know the status(SIG_IGN/SIG_DFL) of a signal within a process.

e.g. if a program has been launched like this:
$nohup ./my_exe&

In this case, is it possible for the process to know that as it has been launched with nohup (i.e. SIGHUP => SIG_IGN)... it should ignore its own handler for SIGHUP if exists.

My application always catches the signal and exits. Smilie

--Vishal
# 2  
Old 01-18-2008
Look at sigaction
Quote:
If the argument act is a null pointer, signal handling is unchanged; thus, the call can be used to enquire about the current handling of a given signal.
# 3  
Old 01-18-2008
I believe this should work.

Code:
[/tmp]$ cat try.cpp 
#include <signal.h>
#include <stdio.h>

int main ()
{
    struct sigaction current;
    ::sigaction (SIGHUP, NULL, &current);
    printf ("SIGHUP:[%d]\n", current.sa_flags);
    return 0;
}
[/tmp]$ gcc -o try try.cpp -lstdc++
[/tmp]$ ./try
SIGHUP:[0]
[/tmp]$

And signum.h tells me 0 corresponds to SIG_DFL

Code:
[/tmp]$ grep SIG_ /usr/include/bits/signum.h
#define SIG_ERR ((__sighandler_t) -1)           /* Error return.  */
#define SIG_DFL ((__sighandler_t) 0)            /* Default action.  */
#define SIG_IGN ((__sighandler_t) 1)            /* Ignore signal.  */
# define SIG_HOLD       ((__sighandler_t) 2)    /* Add signal to hold mask.  */
[/tmp]$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Quiting running process without catching TRAP signal

Hi, I would like to ask, if is it possible to quit running loop in the script any other way than catching the trap signal. Ctrl-C ends only current running instance of process but not whole script. Any clues? (3 Replies)
Discussion started by: smoofy
3 Replies

2. Emergency UNIX and Linux Support

signal between parent process and child process

Hello, everyone. Here's a program: pid_t pid = fork(); if (0 == pid) // child process { execvp ...; } I send a signal (such as SIGINT) to the parent process, the child process receive the signal as well as the parent process. However I don't want to child process to receive the... (7 Replies)
Discussion started by: jackliang
7 Replies

3. Programming

Parent process starts before the child using signal, in C

Hi, i want that the parent process start before the child, this code doesn't work, if the child start before the parent it wait for signal, then the father send the signal SIGALRM and the child catch it and call printf; else the father call printf and send the signal to the child that call its... (1 Reply)
Discussion started by: blob84
1 Replies

4. Programming

how can i make that a process child send a signal?

I'm trying to do a program that makes activate an signal (SINGALARM) when the next child of a son appears but this not works. I have to caught the next child o the other (pid), to send a singnal which inform a menssage. It's anything worng in the code? thanks. the code: #include... (2 Replies)
Discussion started by: marmaster
2 Replies

5. Programming

C -- signal and background process

Hi all, Does a background process send a signal to its parent when completed? If so, how might i capture this signal? I'm trying to write shell in c so that when a background process finishes, it prints a message to the console. Thanks in advance for any advice. (1 Reply)
Discussion started by: jmelai
1 Replies

6. UNIX for Dummies Questions & Answers

Sending signal from child to parent process!

Hi All, I facing a problem in handling signals between parent process communication. I am trying to send a signal(SIGINT) from child to parent. I am using kill function to do so and I am trying to read the signal using sigaction(). But the program is ending abruptly and I am not able to figure out... (4 Replies)
Discussion started by: vkn_1985
4 Replies

7. AIX

process caught signal 5

Hello, We are using AIX 5.2 ML 7. One of the process in its log file said the following and stopped running. Caught signal=5, exiting. What would cause the signal 5 to be generated on an AIX box. Please advise. Thx Jerardfjay (2 Replies)
Discussion started by: jerardfjay
2 Replies

8. Programming

catching a signal from child process

i am creating children processes using fork system call every child i create goes to sleep for random time. when child stops running how can i catch his signal and turminate the child (2 Replies)
Discussion started by: emil2006
2 Replies

9. UNIX for Advanced & Expert Users

catch SIGCHLD signal in parent process

I want to catch SIGCHLD signal in parent process. I can't use wait() system call to catch SIGCHLD according to project requirment. Operating system linux 3.1 can any one have a solution for this. Thanking you, ranjan (2 Replies)
Discussion started by: ranjan
2 Replies

10. Programming

signal in process communication

signal in process communication: I 'm a example in sun_unix that signal in process communication It's here down but I only have freebsd in my machine. how can i do the same in freebsd eg: #include <stdio.h> #include <signal.h> #include <unistd.h> int main( void ){ void... (2 Replies)
Discussion started by: a9711
2 Replies
Login or Register to Ask a Question