pause()--Suspend Process Until Signal Received


  Syntax
 #include <unistd.h>

 int pause( void );

  Service Program Name: QPOSSRV1

  Default Public Authority: *USE

  Threadsafe: Yes

The pause() function suspends processing of the calling thread. The thread does not resume until a signal is delivered whose action is to call a signal-catching function, end the request, or terminate the process. Some signals can be blocked by the thread's signal mask. See sigprocmask()--Examine and Change Blocked Signals for details.

If an incoming unblocked signal has an action of end the request or terminate the process, pause() never returns to the caller. If an incoming signal is handled by a signal-catching function, pause() returns after the signal-catching function returns.


Authorities and Locks

None.


Parameters

None.


Return Value

There is no return value to indicate successful completion.


Error Conditions

If pause() returns, errno indicates the following:

-1

pause() was not successful. The errno variable is set to indicate the reason.

[EINTR]

Interrupted function call.

A signal was received and handled by a signal-catching function that returned.

[ENOTSIGINIT]

Process not enabled for signals.

An attempt was made to call a signal function under one of the following conditions:


[EWOULDBLOCK]
Operation would have caused the process to be suspended. The current thread state would prevent the signal function from completing.

Usage Notes

The pause() function enables a process for signals if the process is not already enabled for signals. For details, see Qp0sEnableSignals()--Enable Process for Signals. If the system has not been enabled for signals, pause() is not successful, and an [ENOTSIGINIT] error is returned.


Related Information


Example

The following example suspends processing using the pause() function and determines the current time.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <time.h>

void catcher( int sig ) {
    printf( "Signal catcher called for signal %d\n", sig );
}

void timestamp( char *str ) {
    time_t t;

    time(&t);
    printf( "The time %s is %s\n", str, ctime(&t) );
}

int main( int argc, char *argv[] )  {

    struct sigaction sigact;

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

    alarm( 10 );

    timestamp( "before pause" );
    pause();
    timestamp( "after pause" );

    return( 0 );
}

Output:

    The time before pause is Sun Jan 22 11:09:08 1995
    Signal catcher called for signal 14
    The time after pause is Sun Jan 22 11:09:18 1995


API introduced: V3R6

[ Back to top | UNIX-Type APIs | APIs by category ]