hard mode can be interrupted by signals after the intr option is set. you can check the time of the STAT command in another thread. Once the time exceeds the threshold, the SIGINT signal is sent.
However, the test shows that in a multi-threaded environment, the SIGINT is sent to the specified thread using pthread_kill (TID, SIGINT) to attempt to interrupt stat.
signals cause termination of the processing process if no action is taken by the process in response to the signal. some signals stop the processing process and other signals can be ignored. each signal has a default action which is one of the following:
The signal is discarded after being passed ed
The process is terminated after the signal is already ed
A core file is written, then the process is terminated
Stop the process after the signal is already ed
Each signal defined by the syste
In Windows, signal and piaoger have never had a chance to use it. Today, since we have encountered it in a console program, it is necessary to take a look at the world and take notes:
> Signals in Windows (SIGNAl)
A signal is a message generated by itself or from outside the process while the process is running.
The signal is a software simulation of hardware interruption (soft interruption ). Each signal is represented by an integer constant macro starting with sig, such as sigchld and
Signal, signal Korean DramaBasic concepts of signals:Each signal has a number and a macro definition name, which can be found in signal. h. Run the kill-l command to view the signal list defined in the system: 1-31 is a common signal; 34-64 is a real-time signal. All signals are sent by the operating system!Three Signal Processing Methods: Ignore the signal, directly execute the default action of the process for the signal, and execute custom actions;
Signal generation conditions:1. When you pre
, but the signal has no priority. All signals are equal;
(2) The signal processing program runs in the user State, while the interrupt processing program runs in the core State;
(3) The interrupt response is timely, and the signal response usually has a large time delay.
Common Linux signals and their key values:
01 SIGHUP pending (hangup)
02 SIGINT interrupted. When you press ^ c or ^ break from the keyboard
03 SIGQUIT exits. When the user presses th
In. POSIX.1 requires system to ignore SIGINT and SIGQUIT and block SIGCHLD.
Instance
Use the systemscripts in http://www.cnblogs.com/nufangrensheng/p/3512291.html to use the ed (1) Editor. (Ed has been a UNIX component for a long time. The reason for calling it here is that it is an interactive program that captures the interrupt and exit signals. If you call ed from shell and type the interrupt character, it captures the interrupt signal and prints
Once, it was tortured by the system () function, because the system () function was not well understood. Simply knowing that using this function to execute a system command is not enough, it is not sufficient, its return value, the return value of the command it executes, and the reason for the failure of the command execution, which is the point. Originally because of this function risk is more, so abandon not use, use other method. Let's not say what I'm using here, it's important to understan
value of SIGINT is 2, this command sends the SIGINT signal to the specified process)--The signals are all integers.//Capturing signals#include #include#includestring.h>#include#include#includevoidCatch_signal (intSign ) { Switch(sign) { Casesigint:printf ("SIGINT signal\n"); Exit (0); Break; Casesigalrm:printf ("SIGALRM signal\n"); Break; }}intMainintArgCh
#defineAlarm_time 10//database An array group information
Char*Db_list[num];//the number of databases currently backed up
intRead_num;//whether the user stops the backup
intIsbreak =0; //Request Content
voidmalloc_dblist ();//release the requested memory
voidfree_dblist ();//Read Database Information
voidreaddbfile ();//Model processing function
voidSignhandler (intSIG); //log The PID information of the program running
intRecordpid (intpid); //get PID information when the program runs
intReadpi
Signal processing is a feature of Linux programs. Signal processing is used to simulate the interrupt function of the operating system. To use the signal processing function, all you have to do is fill out a signal processing function.1#include 2#include 3#include 4#include 5 6 intFlag =1; 7 8 voidFuncintSig)9 { Tenprintf"I get a signal!\n"); OneFlag =0; A } - - intMain () the { - signal (SIGINT, func); -printf"pid:%ld\n",(Long) Ge
, after sigsuspend, the process hangs there, waiting for the open signal to wake up. After receiving the signal, the system restores the current signal set to its original, and then calls the handler function.
Stevens in the Advanced Programming for UNIX environment. "If a signal is caught and if the signal handler returns, then Sigsuspend returns and the SIG Nal Mask of the "process is" set to its value before the called to Sigsuspend. "Because the Sigsuspend is atomic operation, so this is th
Http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.9.html.
Author: Eric Huss
Chinese translator: Liu jinhong poechant
Copyright Disclaimer: the original text in this article is copyrighted by Eric Huss, and the Chinese translation is copyrighted by poechant. Reprinted please indicate from "LIU Da's csdn blog": http://blog.csdn.net/poechant
9. Signal. h
The header file signal is used to process the signal generated when the program is running.
MACRO:
Sig_dfl
Sig_err
Sig_ign
SIGABRT
Sigfpe
Sigill
was generated
* Code. At this moment, the subthread uses the original process information of the main thread. Therefore, the subthread will still respond to the SIGINT and sigterm signals. Therefore, when
* When we use Ctrl + C to send a SIGINT signal, the main process does not process the signal, and the sub-process (thread) performs default processing, that is, exit.
* When a child process exits, it s
similar to the following code:
# Include
......
Void sig_handler (int sig ){......}
Int main (int argc, char ** argv)
{
Struct sigaction sig_act;
......
Sigemptyset ( sig_act.sa_mask );
Sig_act.sa_handler = sig_handler;
Sig_act.sa_flags = 0;
......
}
For more information, see the sigaction man manual.
Supplement:
In short:
// Customize the exit functionSigact. sa_handler = mysighandler;Sigemptyset ( sigact. sa_mask );Sigact. sa_flags = 0;Sigact
be blocked by the process during the process of calling the processing function of the signal.
Sa_flags: specifies various options for signal processing. For specific options, refer to the sigaction function manual.
Sa_sigaction: An Alternative signal processing function. If sa_flags sets sa_siginfo, this function is called; otherwise, sa_handler is called.
Let's look at an example,
#include
In the above sigactiondemo. in the C program, we call the sigaction function to set the p
:
(1) The interruption has a priority, but the signal has no priority. All signals are equal;
(2) The signal processing program runs in the user State, while the interrupt processing program runs in the core State;
(3) The interrupt response is timely, and the signal response usually has a large time delay.
Common Linux signals and their key values:
01 SIGHUP pending (hangup)
02 SIGINT interrupted. When you press ^ c or ^ break from the keyboard
0
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.