Program stability.
To enhance the stability of the program, the reentrant function should be used in the signal processing function.The reentrant (reentrant) function should be used in the signal processing program (note: the so-called reentrant function is a process that can be called by multiple tasks, when a task is called, do not worry about data errors ). After receiving the signal, the process jumps to the signal processing function and runs it. If the non-reentrant function is used in the signal processing function, the signal processing function may modify the data that should not be modified in the original process, in this way, when the process returns and then executes from the signal processing function, unexpected consequences may occur. Non-reentrant functions are considered unsafe functions in signal processing functions.
Most functions that meet the following conditions are not reentrant: (1) use static data structures, such as getlogin (), gmtime (), getgrgid (), getgrnam (), getpwuid () and getpwnam (). (2) The malloc () or free () function is called during function implementation. (3) The standard I/O function is used for implementation. The open group considers the following functions as reentrant:
_ Exit (), access (), alarm (), cfgetispeed (), cfgetospeed (), cfsetispeed (), cfsetospeed (), chdir (), chmod (), chown (), close (), creat (), DUP (), dup2 (), execle (), execve (), fcntl (), fork (), fpathconf (), fstat (), fsync (), getegid (), geteuid (), getgid (), getgroups (), getpgrp (), getpid (), getppid (), getuid (), kill (), Link (), lseek (), mkdir (), mkfifo (),
Open (), pathconf (), pause (), pipe (), raise (), read (), rename (), rmdir (), setgid (), setpgid (), setsid (), setuid (), sigaction (), sigaddset (), sigdelset (), sigemptyset (), sigfillset (), sigismember (), signal (), sigpending (), sigprocmask (), sigsuspend (), sleep (), Stat (), sysconf (), tcdrain (), tcflow (), tcflush (), tcgetattr (), tcgetpgrp (), tcsendbreak (), tcsetattr (), tcsetpgrp (), time (), times (),
Umask (), uname (), unlink (), utime (), wait (), waitpid (), write ().
Even if the signal processing functions use "security functions", you must also note that when entering the processing function, you must first save the errno value and restore the original value at the end. Because the errno value may be changed at any time during signal processing. In addition, longjmp () and siglongjmp () are not listed as reentrant functions, because other calls to the two functions are not guaranteed to be safe.