Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Library Function - pause()

C Library Function - pause()

C Standard Library - <signal.h> C Standard Library -

pause is a function in the C standard library used to suspend a process (pause execution) until a signal is caught. This function is defined in header.

Syntax

int pause(void);

Parameters

pause The function takes no arguments.

Return Value

Example

The following is an example of using pause An example program for the function. This program sets up a signal handler that, upon catching a SIGINT signal (typically triggered by Ctrl+C), releases the suspension.

Example

#include

#include

#include

// Signal handler

void

handle_sigint

(

int

sig

)

{

   

printf

(

"Caught signal %d\n"

,

sig

)

;

}

int

main

(

)

{

   

// Set up the signal handler for SIGINT

    signal

(

SIGINT

,

handle_sigint

)

;

   

// Suspend the process, waiting for a signal

   

printf

(

"Waiting for SIGINT (press Ctrl+C)...\n"

)

;

    pause

(

)

;

   

printf

(

"Exiting...\n"

)

;

   

return

0

;

}

After compiling and running the program, the output will be:

Waiting for SIGINT (press Ctrl+C)...

When Ctrl+C is pressed (sending a SIGINT signal), the output will be:

Explanation

Notes

C Standard Library - <signal.h> C Standard Library -