Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Several of my regular programs crash (on a regular basis) with the message "User defined signal 1". I know there is a nohup command, but is there a nousr1 command? Or something which will do something like nohup but with USR1?

share|improve this question
The better question might be what is sending it the usr1 signal in the first place? If nothing is, the exit message may simply be misleading. – Grant Aug 5 '14 at 3:28
Sounds like you might have some serious problems in your "regular programs" ... simply disabling signals may not correct or enable the underlying applications to properly function. I'd strongly suggest that you examine your environment CAREFULLY before just disabling things. – mdpc Aug 5 '14 at 3:49
@Grant: I agree. Is there a utility which can tell me what is sending these signals? – user2624632 Aug 5 '14 at 17:23
up vote 3 down vote accepted

A simple hacky solution to have the utility analogous to nohup, but for SIGUSR1, would be to get a copy of coreutils source, unpack it, do

sed -i 's/SIGHUP/SIGUSR1/' /path/to/coreutils/src/nohup.c

, optionally also change the output file name

sed -i 's/nohup\.out/nousr1.out/g' /path/to/coreutils/src/nohup.c

, compile this source and install the newly-compiled nohup binary to /usr/bin/nousr1:

cp /path/to/coreutils/src/nohup /usr/bin/nousr1

After this, as I checked, sleep 1000 exits on USR1, while nousr1 sleep 1000 is immune to this signal.

share|improve this answer
The main functionality of nohup, by the way, is to disassociate the process from the terminal so it isn't sent SIGHUP in the first place. That it also sets up a signal handler is an additional bonus, but should be unnecessary. – Simon Richter Aug 5 '14 at 15:00
@SimonRichter If you remove the signal(SIGHUP,SIG_IGN); call in nohup.c, the process will receive the SIGHUP. What nohup does aside from ignoring the signal is just reopening the stdin,stdout,stderr descriptors as non-terminal files. It doesn't really disassociate the process from the terminal in any special way. I.e., the process will be sent SIGHUP when terminal hangs up. On the other side there's bash, which does similar thing with disown command, but I'm not sure how it is implemented — maybe in the way you mean. – Ruslan Aug 5 '14 at 15:34
This seems to work well. – user2624632 Aug 16 '14 at 0:03

How about the shell trap built-in command?

trap 'echo "Thou shalt not USR1 me"' USR1 
share|improve this answer
Good idea, but it didn't work. The process exited anyway with "User defined signal 1". – user2624632 Aug 7 '14 at 17:39
Signal handlers (other than SIG_IGN and SIG_DFL) are not inherited by child processes. – aecolley Aug 16 '14 at 11:51

You need to use the form of the trap command with a blank argument. Try this:

trap '' SIGUSR1; myprogram

This will ignore the SIGUSR1 signal which is what you're trying to do. Although I agree with the commenters that there is probably more going on here than meets the eye.

The incorrect form:

trap 'echo ...' SIGUSR1; myprogram

will still allow myprogram to receive the SIGUSR1 but the shell will then execute the echo from the trap command.

share|improve this answer
This seems to work well. – user2624632 Aug 16 '14 at 0:04
Oops, I spoke too soon. I was running trap '' SIGUSR1; gvimdiff file1 file2 and Vim died with "Vim: Caught deadly signal USR1". – user2624632 Aug 16 '14 at 19:20
Hmmm, looking at the source-code at it seems that VIM re-enables the USR1 signal and treats it as a fatal error. Your only hope would seem to be if you can make the OS refuse to deliver the USR1 signal. I don't know if there is something out there that can provide that functionality. – Adrian Pronk Aug 17 '14 at 10:15
More info here: – Adrian Pronk Aug 17 '14 at 19:41
Adrian Pronk: it's not just Vim; it's also Firefox, and Aqualung, and Thunderbird, and some others. But not other apps, such as Konsole, which runs forever. – user2624632 Aug 21 '14 at 0:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.