pause() — Suspend a process pending a signal

Standards

Standards / Extensions C or C++ Dependencies

POSIX.1
POSIX.4a
XPG4
XPG4.2
Single UNIX Specification, Version 3

both

POSIX(ON)

Format

#define _POSIX_SOURCE
#include <unistd.h>

int pause(void);

General description

Suspends execution of the calling thread. The thread does not resume execution until a signal is delivered, executing a signal handler or ending the thread. Some signals can be blocked by the process's thread. See sigprocmask() — Examine or change a thread for details.

If an incoming unblocked signal ends the thread, pause() never returns to the caller. If an incoming signal is handled by a signal handler, pause() returns after the signal handler returns.

Returned value

If pause() returns, it always returns -1 and sets errno to EINTR, indicating that a signal was received and handled successfully.

Example

CELEBP02
⁄* CELEBP02

   This example suspends execution and determines the
   current time.

 *⁄
#define _POSIX_SOURCE
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <time.h>

void catcher(int signum) {
  puts("inside catcher...");
}

void timestamp() {
  time_t t;
  time(&t);
  printf("the time is %s", ctime(&t));
}

main() {
  struct sigaction sigact;

  sigemptyset(&sigact.sa_mask);
  sigact.sa_flags = 0;
  sigact.sa_handler = catcher;
  sigaction(SIGALRM, &sigact, NULL);

  alarm(10);
  printf("before pause... ");
  timestamp();
  pause();
  printf("after pause... ");
  timestamp();
}
Output:
before pause... the time is Fri Jun 16 09:42:29 2001
inside catcher...

after pause... the time is Fri Jun 16 09:42:39 2001

Related information