Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

20. Signals: Fundamental Concepts > Other Ways of Sending Signals: raise() and ...

Other Ways of Sending Signals: raise() and killpg()

Sometimes, it is useful for a process to send a signal to itself. (We see an example of this in Handling Job-Control Signals.) The raise() function performs this task.

#include <signal.h>

int raise(int sig);

Note

Returns 0 on success, or nonzero on error

In a single-threaded program, a call to raise() is equivalent to the following call to kill():

kill(getpid(), sig);

On a system that supports threads, raise(sig) is implemented as:

pthread_kill(pthread_self(), sig)

We describe the pthread_kill() function in Sending a Signal to a Thread, but for now it is sufficient to say that this implementation means that the signal will be delivered to the specific thread that called raise(). By contrast, the call kill(getpid(), sig) sends a signal to the calling process, and that signal may be delivered to any thread in the process.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint