I have a question. The desired value is running every 5 seconds...That's how it's written If you write the code and the name is alarm.c, if you do alarm 5, the value of *argv goes to 5 If we execute it, wouldn't SIGALARM be executed on signal after 5 seconds through alarm (*argv) in the main function and exit (0)? Why does running keep coming out when I run it and it can't end...
void sig(int signal)
int main(int argc, char *argv)
return 0; }unix
alarm(unsigned) accepts unsigned integers as call factors.
*argv is treated as an integer as char. When executed with
./alarm5, the iskey code 53 for
'5' instead of an integer 5.
alram (*argv) generates a signal after 53 seconds.
Therefore, you should call it by converting a string into an integer, as follows:
As an admonition,
exit() should not be used in the signal handler. Please refer to the following link.
© 2022 pinfo. All rights reserved.