how to use kill SIGUSR2 in bash?

SIGUSR2 is architecture depended and can have a value out of 31, 12 or 17. This is described in man 7 signal. You'll have to find out which value is appropriate for your system. Usually this is done by having a look into:

/usr/include/asm/signal.h 

On my system - Ubuntu 12.04 AMD 64 - it has a value of 12:

#define SIGUSR2     12

Once you know the proper numeric value for SIGUSR2 on your system, you can send this signal using:

kill -SIGNO PID
# In this case
kill -12 PID

On my Linux box it works.

I ran an infinite loop (pid = 4574), then I ran

#!/bin/bash
kill -l | grep USR2
kill -SIGUSR2 4574

kill -l has showed the signal and kill -SIGUSR2 has sent the signal (killing the process).

Check if you are running Bash or some other shell (e.g., dash, busybox, etc.)


Cross-platform way to do this: use -s without the SIG prefix. E.g.,:

kill -s USR2 $pid

This seems to work on both MacOS and linux.

Tags:

Linux

Shell

Kill