1. alarm ()
Before you reentrant a function, let's take a look at the usage of the alarm () function:
# Include <unistd. h>
Unsigned int alarm (unsigned int seconds)
The system calls alarm to schedule the kernel to send a SIGALRM signal to the calling process after the specified seconds. If the specified seconds parameter is 0, the SIGALRM signal is no longer sent. The last setting will cancel the previous setting. The returned value is the time remaining between the last scheduled call and sending, or 0 is returned because there is no previous scheduled call.
Note: in use, alarm is only set to send a signal once. If you want to send a signal multiple times, you must use alarm for multiple calls.
Man help description:
DESCRIPTION
Alarm () arranges for a SIGALRM signal to be delivered to the calling
Process in seconds.
If seconds is zero, no new alarm () is scheduled.
In any event any previusly set alarm () is canceled.
RETURN VALUE
Alarm () returns the number of seconds remaining until any previusly
Scheduled alarm was due to be delivered, or zero if there was no previ-
Ously scheduled alarm.
Example:
#include <unistd.h><sys/stat.h><sys/wait.h><sys/types.h><fcntl.h><stdlib.h><stdio.h><errno.h><.h><signal.h> ERR_EXIT(m) \ ( handler( main( argc, * (signal(SIGALRM, handler) == handler(
Result:
<Sys/stat. h> <sys/wait. h> <sys/types. h> <fcntl. h> <stdlib. h> <stdio. h> <errno. h> <. h> <signal. h> ERR_EXIT (m) \ (handler (main (argc, * ={,={, (signal (SIGALRM, handler) ==== handler (
Result:
The program also creates a struct, sets a global variable, and then uses two local variables in the main function to assign values to the global variables respectively, because this assignment operation can be interrupted, for example, the assignment of each struct can be considered as two steps:
G_data.a = zeros.;
G_data. B = zeros. B;
So when g_data.a = one. a. After the operation is complete and interrupted, run to execute the processing function and call unsafe_fun () in the processing function to print the global variable value. The result is that the value of global variable a has changed, the B value is still not here and changed, so 1, 0 appears.
So the results are uncertain.