Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a signal to a process in C?

Tags:

c

signals

I need to send a signal to a process and when the process receives this signal it does some things, how is this best achieved in C?

like image 986
Samantha Catania Avatar asked Oct 08 '11 12:10

Samantha Catania


People also ask

How do you send a signal to a process?

Sending signals to foreground processesPressing Ctrl+C sends an Interrupt signal (SIGINT) to the process and the process terminates.

How do you send a signal to a process in C ++?

The way to send a signal to a process is kill(pid, signal); However, you should be aware that signals are not a robust means of inter-process communication except for parent-to-direct-child messages due to inherent race conditions.

What does signal () do in C?

signal() sets the disposition of the signal signum to handler, which is either SIG_IGN, SIG_DFL, or the address of a programmer- defined function (a "signal handler"). If the signal signum is delivered to the process, then one of the following happens: * If the disposition is set to SIG_IGN, then the signal is ignored.


2 Answers

The way to send a signal to a process is kill(pid, signal); However, you should be aware that signals are not a robust means of inter-process communication except for parent-to-direct-child messages due to inherent race conditions. Pipes, files, directories, named semaphores, sockets, shared memory, etc. all provide greatly superior approaches to inter-process communication.

like image 176
R.. GitHub STOP HELPING ICE Avatar answered Sep 28 '22 01:09

R.. GitHub STOP HELPING ICE


If you happen to be on one of the Unix variants, the following man pages will help:

man 2 kill
man 2 signal
man 2 sigvec
like image 38
wildplasser Avatar answered Sep 28 '22 02:09

wildplasser