Skip to main content

Signal

Functions#

Name
intkill(pid_t pid, int signo)
pid_twaitpid(pid_t pid, int * stat_loc, int options)
pid_twait(int * stat_loc)
intpthread_kill(pthread_t thread, int signo)
intsigqueue(pid_t pid, int signo, const union sigval value)
intsigwait(const sigset_t set, int sig)
intsigtimedwait(const sigset_t set, siginfo_t info, const struct timespec * timeout)
intsigwaitinfo(const sigset_t set, siginfo_t info)
_sig_func_ptrsignal(int sig, _sig_func_ptr func)
intsigaction(int sig, const struct sigaction act, struct sigaction oact)
intpthread_sigmask(int how, const sigset_t set, sigset_t oset)
intsigprocmask(int how, const sigset_t set, sigset_t oset)
intsigpending(sigset_t * set)
intsigsuspend(const sigset_t * sigmask)

Functions Documentation#

kill#

int kill(    pid_t pid,    int signo)

Return: Zero or -1 with errno (see Errno) set to:

  • EINVAL: signo is not a valid signal number
  • ESRCH: pid is not a valid process id

This function sends the signal signo to the process pid.

waitpid#

pid_t waitpid(    pid_t pid,    int * stat_loc,    int options)

wait#

pid_t wait(    int * stat_loc)

pthread_kill#

int pthread_kill(    pthread_t thread,    int signo)

Return: Zero or -1 with errno (see Errno) set to:

  • EINVAL: signo is not a valid signal number
  • ESRCH: pid is not a valid process id

This function sends the signal signo to thread. The handler is executed in the context of thread, but the signal effects the entire process. For example,

pthread_kill(8, SIGKILL);

will kill the process that holds thread 8. The exit handler will be executed on thread 8's stack.

sigqueue#

int sigqueue(    pid_t pid,    int signo,    const union sigval value)

Return: Zero or -1 with errno (see Errno) set to:

  • EINVAL: signo is not a valid signal number
  • ESRCH: pid is not a valid process id

This function sends the signal signo to the process pid. The signal value is specified by value.

sigwait#

int sigwait(    const sigset_t * set,    int * sig)

Return: Zero or -1 with errno (see Errno) set to:

  • EINVAL: set contains an invalid or unsupported signal

This function checks to see if any signals in set are pending. If a signal is pending, it is cleared and the signal number is written to *sig, and the thread is not blocked.

If no signals in set are pending, the thread is blocked until a signal becomes pending.

The signals defined by set should be blocked when this function is called (see pthread_sigmask() and sigprocmask()).

sigtimedwait#

int sigtimedwait(    const sigset_t * set,    siginfo_t * info,    const struct timespec * timeout)

Return: Zero or -1 with errno (see Errno) set to:

  • EINVAL: set contains an invalid or unsupported signal
  • EAGAIN: timeout expired before any signals arrived
  • EINTR: a signal, not in set, was caught

This function checks to see if any signals in the set are pending. If a signal is pending, it is cleared and the signal information is written to info, and the function returns without blocking.

If no signals in set are pending, the task is blocked until a signal becomes pending or until the timeout expires.

Todothe sigcault flag should not be in a protected area of memory

sigwaitinfo#

int sigwaitinfo(    const sigset_t * set,    siginfo_t * info)

Return: Zero or -1 with errno (see Errno) set to:

  • EINVAL: set contains an invalid or unsupported signal
  • EINTR: a signal, not in set, was caught

Todo: Add error checking

This function checks to see if any signals in set are pending. If a signal is pending, it is cleared and the signal info is written to info, and the function returns without blocking.

If no signals in set are pending, the task is blocked until a signal becomes pending.

signal#

_sig_func_ptr signal(    int sig,    _sig_func_ptr func)

Return: Zero or SIG_ERR with errno (see Errno) set to:

  • EINVAL: sig is not a valid signal or is a signal that cannot be caught.

This function sets the handler for sig to func.

sigaction#

int sigaction(    int sig,    const struct sigaction * act,    struct sigaction * oact)

Return: Zero or SIG_ERR with errno (see Errno) set to:

  • EINVAL: sig is not a valid signal or is a signal that cannot be caught.
  • EINTR: a signal, not in set, was caught

This function sets the action for sig to act. The previous action is written is oact if oact is not NULL. Using this function will override any handler previously set with signal().

pthread_sigmask#

int pthread_sigmask(    int how,    const sigset_t * set,    sigset_t * oset)

Return: Zero or SIG_ERR with errno (see Errno) set to:

  • EINVAL: how is not one of SIG_BLOCK, SIG_SETMASK, or SIG_UNBLOCK

This function sets the signal mask for the current thread.

sigprocmask#

int sigprocmask(    int how,    const sigset_t * set,    sigset_t * oset)

Return: Zero or SIG_ERR with errno (see Errno) set to:

  • EINVAL: how is not one of SIG_BLOCK, SIG_SETMASK, or SIG_UNBLOCK

This function sets the signal mask for the current thread. This function should only be called in single threaded applications.

Todothe calling thread must be a process (thread 0 of the process)

sigpending#

int sigpending(    sigset_t * set)

Return: -1 with errno set to EINTR otherwise never returns

This function writes the calling thread's current pending set to set. It then waits for a signal to arrive. If the action for the signal is to terminate, then this function never returns. If the action is to execute a signal catching function, the signal catching function is executed and the signal mask for the thread is restored before returning.

sigsuspend#

int sigsuspend(    const sigset_t * sigmask)

Updated on 18 September 2021 at 21:44:10 MDT