Signal Names


 
Thread Tools Search this Thread
Top Forums Programming Signal Names
# 1  
Old 11-02-2004
Signal Names

Hi everyone,

Is there a variable or built in function in the Unix env. for me to obtain the name of a signal that is caught? As far as I understand only a numeric value of the signal is returned to the handler.

For example:

Code:
void handler (int signum)
            {
                    signal(SIGINT, handler);
                    cout<<"Signal: "<<signum<<endl;
            }

            int main (int argc, char* argv[])
            {
                  signal(SIGINT, handler);
                  for ( ;; )
                      pause();
            }

with the above code, only the number printed. I would like to get the name of the signal... i'm hoping that there is a built-in function for me to get this so that i won't need to manually code the conversion part in.

Also, do i need to have ( signal(SIGINT, handler); ) and a handler function set for EVERY signal that I want to catch? Is there a way for me to catch all the signals using one handler? would the use of sigaction() and sigprocmask() satisfy my requirements?

Thank you for your time and help.
# 2  
Old 11-02-2004
There is nothing such as 'name of the signal'. I guess you are refferring to the defined macros for the signal numbers.

#define SIGHUP 1 /* hangup */
#define SIGINT 2 /* interrupt (rubout) */
#define SIGQUIT 3 /* quit (ASCII FS) */

There are couple of ways to find out the description of the caught signal. One can call below functions to get the description:

void psignal(int sig, const char *s);
void psiginfo(siginfo_t *pinfo, char *s);

These functions are defined in <siginfo.h>

Coming to your second question:

As per my understanding, there is no generic function to catch all the signals. It is necessary to specify the signal you want handle.

Hope this helps.

Last edited by A452917; 11-02-2004 at 06:48 PM..
# 3  
Old 11-03-2004
Thank you for your suggestion. i'll try those functions out and see.

any other suggestion would be greatly appreciated.

Cheers! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

2. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

3. UNIX for Dummies Questions & Answers

signal() and sigsetjmp()

Hi, I am basically new to signals in UNIX. My question is, should the signal() command be called only once in the program? What will happen if it's called multiple times? I am trying to write an alarm program where the signal handler function changes in runtime. It just doesn't work if I... (2 Replies)
Discussion started by: bashdrew
2 Replies

4. Programming

Signal processing

We have written a deamon which have many threads. We are registering for the SIGTERM and trying to close main thread in this signal handling. Actually these are running on Mac OS X ( BSD unix). When we are unloading the deamon with command launchctl, it's sending SIGTERM signal to our process... (1 Reply)
Discussion started by: Akshay4u
1 Replies

5. Programming

RLIMIT_STACK signal's

I'am expecting a signal, but no signal is received when the stack-size reaches 10 bytes. Here in this code i'am setting rlim_cur=10bytes. To be more precise, when it reaches 10 bytes the process must receive a SIGSEGV signal? But i find no signal being received. Am i missing something in this... (0 Replies)
Discussion started by: prajwalps97
0 Replies

6. Shell Programming and Scripting

Killed by signal 15.

Hi all I have Master script, Main script ,and 4 Child script. Master.sh #!/bin/bash /export/home/user/Main.shMain.sh #!/bin/bash /export/home/user/Child1.sh & /export/home/user/Child2.sh & /export/home/user/Child3.sh & /export/home/user/Child4.sh &I run only Master.sh script... (1 Reply)
Discussion started by: almanto
1 Replies

7. Programming

Signal catching

Hi! I want to catch all signals that my program receives print their name and then execute the default handler. Can you help me on that? I've tried the following code: #include <stdio.h> #include <unistd.h> #include <signal.h> void (*hnd)(int i); char signals = { "SIGHUP",... (7 Replies)
Discussion started by: dark_knight
7 Replies

8. Programming

Signal Problem

I am using the signal function, and passing it a function named quit procedure...I get the following warning.... passing arg2 of signal from incompatible pointer type... void quit_procedure(void); //this is the way i define my prototype... signal(SIGINT, quit_procedure); Please guide... (5 Replies)
Discussion started by: jacques83
5 Replies

9. UNIX for Advanced & Expert Users

Kill Signal

Hello, I'm doing a project of OS simulation (Process Scheduling, to be very specific). Can anyone, please, explain what exactly happens in the background when we see "Sending all processes the KILL signal...........". How is it sent to each process? Is it that something like a boolean is stored... (3 Replies)
Discussion started by: ameya
3 Replies

10. UNIX for Dummies Questions & Answers

Alarm signal

Hi, when I execute a script on unix AIX, I've got an error message: "Execution: 85328 Signal d'alarme". If I edit this file with "vi", I ve got the same error after a while (about 1 minute). If I try with another user I still have the problem. But if I rename this file, no problem. My... (5 Replies)
Discussion started by: cgsteph
5 Replies
Login or Register to Ask a Question