Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C- what exactly is SIGUSR1 syntactically

Tags:

c

kill

signals

When I use SIGUSR1 in the kill() or signal() functions, what is it doing? Is it a macro? I read that it was user defined, but where is it defined? Can I make a SIGUSR10 (or programatically make an "array" of different signal types)?

like image 248
user3475234 Avatar asked Sep 09 '14 04:09

user3475234


People also ask

What is SIGUSR1 in C?

The SIGUSR1 and SIGUSR2 signals are set aside for you to use any way you want. They're useful for simple interprocess communication, if you write a signal handler for them in the program that receives the signal. There is an example showing the use of SIGUSR1 and SIGUSR2 in Signaling Another Process.

What is SIGUSR1 in Python?

10 (SIGUSR1): user-defined signal. 11 (SIGSEGV): segmentation fault due to illegal access of a memory segment. 12 (SIGUSR2): user-defined signal. 13 (SIGPIPE): writing into a pipe, and nobody is reading from it. 14 (SIGALRM): the timer terminated (alarm)

What is the value of SIGUSR1?

SIGUSR1 value is platform dependent. SIGUSR1 can be 30, 10, or 16. For example, x86-based Linux defines SIGUSR1 as 10.

What is kill SIGUSR1?

Save this answer. Show activity on this post. kill -USR1 %1 sends the "user-defined signal #1" (a.k.a. "SIGUSR1") to the first background child process of the current shell process. If that background process has set up a signal-handler function for the USR1 signal, that function will be run.


2 Answers

User defined signals means that these signals have no definite meaning unlike SIGSEGV, SIGCONT, SIGSTOP, etc. The kernel will never send SIGUSR1 or SIGUSR2 to a process, so the meaning of the signal can be set by you as per the needs of your application. All these uppercase SIG constants are actually macros which will expand to an integer indicating a signal number in the particular implementation. Although user defined signals do not necessarily need to be defined, the signal numbers are already fixed in a particular implementation, and they can be safely re-purposed since they will not be sent by anything except for the user.

Traditionally, there have been two user-defined signals: SIGUSR1 and SIGUSR2. However, recent implementations have something called "POSIX realtime signals" which offer several more user-defined signals.

like image 50
phoxis Avatar answered Sep 28 '22 11:09

phoxis


SIGUSR is, as the name implies, a signal reserved for use by the user (developer), without any "special" pre-defined meaning. You can't make 10 of them, on most POSIX systems there are exactly two - SIGUSR1 and SIGUSR2.

The symbol itself may or may not be a macro expansion, but will end up being a numeric value assignment-compatible with int.

To use it in a meaningful way, you will need to write a signal handler. See the signal() manpage for details on how to do this.

like image 32
BadZen Avatar answered Sep 28 '22 09:09

BadZen