C language Pause () function: Let the process pause until the signal appears
header file:
To define a function:
Function Description: Pause () will suspend the current process (go to sleep state) until it is interrupted by a signal (signal).
Return value: Returns only-1.
Error code: EINTR has a signal arrival interrupt this function.
C language Alarm () function: Set signal transmission alarm Clock
header file:
To define a function:
unsigned int alarm (unsigned int seconds);
Function Description: Alarm () is used to set the signal SIGALRM to the current process after the number of seconds specified by the parameter seconds. If the parameter seconds is 0, the previous set alarm is canceled and the remaining time is returned.
Return value: Returns the number of seconds left before the alarm, and returns 0 if no previous alarm is set.
Example
#include <unistd.h>
#include <signal.h>
void handler ()
{
printf ("hello\n");
}
Main ()
{
int i;
Signal (SIGALRM, handler);
Alarm (5);
for (i = 1; i < 7; i++)
{
printf ("Sleep%d ... \ n", i);
Sleep (1);
}
}
Perform:
Sleep 1
... Sleep 2
... Sleep 3
... Sleep 4
... Sleep 5 ... hello sleep
6 ...
C language Sleep () function: Let a process suspend execution for a period of time
header file:
To define a function:
unsigned int sleep (unsigned int seconds);
Function Description: Sleep () pauses the current process until it reaches the time specified by the parameter seconds or is interrupted by a signal.
Return value: Returns 0 if the process pauses to the specified time of the parameter seconds, and returns the number of seconds if a signal is interrupted.