≡ Menu

UNIX / Linux: 3 Ways to Send Signal to Processes

Question: How do I send signal to another process? Can you explain me all available options to send signals to a process in UNIX / Linux environment?

Answer: You can send various signals to processes using one of the methods explains in this article.

1. Send Signal to a Process Using Kill

Use kill command to send a signal to a process. For example, if you want to send USR1 signal to the process “a.out”, do the following.

$ ps -C a.out
  PID TTY          TIME CMD
 3699 pts/1    00:00:00 a.out

$ kill -s USR1 3699

Note: Refer to 4 Ways to Kill a Process – kill, killall, pkill, xkill.

2. Send Signal to a Process from Another Process

You can use the UNIX system call kill (from a C program) to send signal from one process to another. The following C code snippet shows how to use the kill command.

Kill system call takes two arguments: 1) the PID (process id) of the process that needs to be signalled 2) the signal that needs to be send to the process. Kill command returns 0 when it is successful.

int send_signal (int pid)
{
        int ret;
        ret = kill(pid,SIGHUP);
        printf("ret : %d",ret);

}

3. Send Signal to a Process from Keyboard

When a process is running on the terminal, you can send signal to that process from the keyboard by using some specific combination of keys. The following are couple of examples.

  • SIGINT (Ctrl + C) – You know this already. Pressing Ctrl + C kills the running foreground process. This sends the SIGINT to the process to kill it.
  • You can send SIGQUIT signal to a process by pressing Ctrl + \ or Ctrl + Y

You can view the key mappings that sends specific signal to a process using the “stty -a” command as shown below.

$ stty -a | grep intr
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?;
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Kuldeep February 8, 2011, 4:14 am

    Thanx alot sir, for very helpful information…..

  • SaveTheRbtz February 8, 2011, 4:52 am

    Info about signals 0 and -1 may be usable here.

  • Ganesh February 9, 2011, 6:15 am

    hello sir how to install vlc in linux 5

  • Felix Frank February 11, 2011, 6:39 am

    Hi.

    intr and quit are signals, I think, the rest are not. Specifically, there is no shortcut to send a kill signal.

    Also I’d like to add the other useful shortcut: Ctrl+Z for SIGSTOP. Followed by “bg”, it can be used to transfer a foreground process to the background.

    Regards,
    Felix

  • AjayKumar September 5, 2015, 8:15 am

    Second option from command line, may be useful 🙂
    pkill -USR1 -n -x