There is nohup, is there a nousr1 command?

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?


Solution 1:

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.

Solution 2:

How about the shell trap built-in command?

trap 'echo "Thou shalt not USR1 me"' USR1 

Solution 3:

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.