Transferred from: http://www.jb51.net/article/74844.htmIn the LIUNX system in order to execute a command every minute, the most common way is crontab, if you do not want to use Crontab, with colleagues in the program can use the timer to achieve this function, so began to grope, found that need some signal knowledge ...See which signals your Linux supports: kill-l1) SIGHUP 2) SIGINT 3) Sigquit 4) Sigill 5) SIGTRAP6) SIGABRT 7) Sigbus 8) SIGFPE 9) SIGK
the handler in the defined variable are copied to the handlers property of the Eng object. Finally, the Eng object is successfully returned.5.3 Setting the engine's signal captureBack in the run of the Maindaemon () function, execute the following code:Signal. Trap (Eng. Shutdown)The function of this part of the code is: in the operation of the Docker daemon, set the trap specific signal processing method, the specific signal has sigint,sigterm and S
", I);
Sleep (1);
i++;
}
}
int main ()
{
struct Sigaction act,oldact;
Act.sa_handler = wrkprocess;
Sigaddset (act.sa_mask,sigquit);
Sigaddset (act.sa_mask,sigterm)
act.sa_flags = Sa_nodefer |Sa_resethand;
act.sa_flags = 0;
Sigaction (sigint,act,oldact);
printf ("Main threadid:%d/n", Pthread_self ());
while (1) sleep (5);
return 0;
}
1) When the program is executed, CTRL + C, the first time will not
function that captures the CTRL + C Signal**************************/Void ctrl_c_func (INT signo){Printf ("stop the demo/N ");Main_status = 1; // set the flag bitExit (0 );}
Int ctrl_c_func_init (void){Int ret = 0;Struct sigaction Act;
Act. sa_handler = ctrl_c_func;Sigemptyset ( act. sa_mask );Act. sa_flags = 0;
Ret = sigaction (SIGINT, act, null );}
/***************************** Main program****************************/Int main (INT argc, char **
: the default behavior of the recovery signal is said so much. Let's give an example to illustrate it. The source file is signal1.c, the Code is as follows:
# Include The running result is as follows:
As you can see, the process is not terminated when you press the terminate command (CTRL + C) for the first time, and the output is ouch! -I got signal 2, because the default SIGINT behavior is changed by the signal function, when the process receives th
Simple Analysis of system functions in linux, linuxsystem Functions
1 int 2 __libc_system (const char *line) 3 { 4 if (line == NULL) 5 /* Check that we have a command processor available. It might 6 not be available after a chroot(), for example. */ 7 return do_system ("exit 0") == 0; 8 9 return do_system (line);10 }11 weak_alias (__libc_system, system)
The code is located in glibc/sysdeps/posix/system. c. Here, system is the weak alias of _ libc_system, and _ libc_system
Comparison of two groups of signals in Linux and two groups of signals in Linux
Blog gradually migrated to, independent blog, original address http://www.woniubi.cn/two_groups_signal_difference/
When looking at the signal, I did not pay too much attention to the comparison of different signals. when I saw it again today, I suddenly felt that some signals were very similar and even very confusing. I will take the time to summarize this weekend.The first group disables the process signal.
In commo
-process.
3. Unreliable Signals)
In earlier Unix systems, the signal was unreliable.
Unreliable means that the signal may be lost. That is, the signal occurs, but the process does not capture it.
We hope that the kernel can remember the signal. When we ready, let us know that the signal has occurred and let us process it.
In early systems, there was another problem with the implementation of the signal mechanism: When a signal occurs and a signal processing function is executed, the signal proce
, the chance of error is less, so generally as long as the interface is written, the opportunity to make mistakes is still very low. Of course, we are not saying that the single cycle is useless, on the contrary. Single-cycle mode is one of the most common patterns we use. This development is especially suitable for small tools, small applications, and small scenes. #!/usr/bin/pythonimport osimport sysimport reimport signalimport timeg_exit=0def sig_process (SIG, frame):Globalg_exit g_exit=1Prin
you quit the Linux login, wget can continue to download.In addition, for daemons with terminal disengagement, this signal is used to notify it to reread the configuration file.2)SIGINTA program termination (interrupt) signal, issued when the user types the intr character (usually ctrl-c), to inform the foreground process group that the process is terminated.3)SigquitSimilar to SIGINT, but controlled by the quit character (usually ctrl). The process g
command line)Brkint: (can produce a plug when the command line is interrupted) if IGNBRK is set, break is ignored. If there is no setting, but Brkint is set, then break will cause the input and output queues to be flushed, and if the terminal is a control terminal of a foreground process group, all processes in the process group will receive the SIGINT signal. If neither set IGNBRK nor set Brkint,break will be considered with the NUL word Fu Tongyi,
the child process is stored in the memory address pointed to by the parameter
Option (configuration information): the constant declared in the delivery header file Sys/wait.h
#include #include #include intMainintARGC,Char* argv[]) {//For saving state intStatus//fork a child processpid_t pid = fork ();if(PID = =0) {Sleep ( the);return -; }Else{ while(!waitpid (Pid,status,wnohang)) {Sleep (3);puts("Sleap 3 Seconds"); }if(wifexited (status)) {printf("Child send%d \ n", Wexitstatus (st
In some cases, we don't want our shell scripts to be interrupted at runtime, such as when we write shell feetThis is set to a user's default shell, so that the user can only do one job after entering the system, such as database backup, IWe do not want users to use CTRL + C and so on into the shell state, do what we do not want to do. This is where the signal is used.Processing.Kill-l can list the signal names of the system as follows:[Email protected]:~/script/test$ kill-l1) SIGHUP 2)
signals1. The essence of a signal is a soft interrupt, which can be used as a way to communicate between processes, and more importantly, the signal can interrupt a normal operation of the program, more to deal with the unexpected situation.2. Characteristics of the signal:A. The signal is asynchronous and the process does not know when the signal arrivesB. The process can process the signal, and can send a signal to the specified processC. Each signal has a name and starts with the sig.3. Basi
signal to the terminal output process. The default action for this signal is to terminate the process, so the foreground process group and the process that has terminal output in the background will be aborted. However, this signal can be captured, such as wget can capture the sighup signal, and ignore it, so even if you quit the Linux login, wget can continue to download. In addition, for daemons with terminal disengagement, this signal is used to notify it to reread the configuration file. 2)
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 understand
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.