Http://www.cnblogs.com/taobataoma/archive/2007/08/30/875743.htmlsignal is a very important part of Linux programming, this article will detail the basic concept of signal mechanism, the approximate realization method of Linux to signal mechanism, how to use signal, and several system calls about signal. signal mechanism is a method of transmitting messages between processes, which is called soft interrupt s
signal is a very important part of Linux programming, this article will detail the basic concept of signal mechanism, the approximate realization method of Linux to signal mechanism, how to use signal, and several system calls about signal. signal mechanism is a method of transmitting messages between processes, which is called soft interrupt signal, and some people call it soft interrupt. It can be seen fr
type parameter (that is, the received signal code), which itself is of type void, handler can also be the following two special values:sig_ign Shielding the signalSIG_DFL Restore default behaviorExample 1void handler (int sigNum) { cout RETURN VALUESignal () returns the previous value of the signal handler, or Sig_err on error.In the event of a error, errno is set to indicate the cause.int main (int argc, char *argv[]) { sighandler_t Oldhandler = Signal (
set, the characters are simply printed, including various control characters. This flag is not defined in POSIX.
Isig
If set, the signals SIGINT, Sigquit, and sigtstp that correspond to Intr, quit, and Susp are sent to all processes in the foreground process group of the TTY device.
Noflsh
In general, the input output queue is emptied when the Intr or quit control is received, and the input queue is emptied when the Susp control character is received
Linux system () and Popen () Differences 1. Introduction to System () and Popen ()In Linux we can execute a shell command through system (), and Popen () executes shell commands and communicates through pipelines and shell commands.System (), Popen () gives us a series of processing processes such as fork, exec, waitpid, and so on, so that we only need to focus on the final return result (the function's ret
A signal (signal) is a software interrupt that provides a way to handle asynchronous events and is the only asynchronous communication between processes. In a Linux system, the subsequent signaling mechanism is extended according to the POSIX standard, which can be used to inform not only what happened to a program, but also the process of passing data to it.First, the source of the signalThe source of the signal can have many kinds of test, according
First of all thank you Liao brother this friend to me last night wrote a "talk about the signal mechanism of Linux (a)", before the topic I used the word "analysis", give a person to analyze the feeling of the kernel. I know the skill is not enough, but can not be judged on the Linux kernel source code. After the road is still very long, I still step by step slowly walk,
We already know that we can terminate processes through signals or communicate between processes through signals, the program can also change the default Signal Processing Method by specifying the correlated processing function of the signal, or shield some signals so that they cannot be passed to the process. So how should we set the signal we need to process, and we don't need to deal with any other problems? The signal set function helps us solve these problems. For more information about how
-thread exit................Return 0;
}
After the program runs, it is very strange to find that the program exits immediately after pressing CTRL + C without the information of the Sub-thread exiting.After careful analysis, the problem is that the characteristics of the multi-threaded model in Linux are ignored.
In Linux, a thread is essentially a light weighted process. When a thread is generated, a c
terminals.
When you log on to Linux, the system assigns a Session to the login user ). All programs running on this terminal, including foreground and background process groups, generally belong to this Session. When you log out of Linux, processes in the frontend process group and in the background that are output to the terminal will receive a SIGHUP signal. The default operation of this signal is to te
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 tak
sighup signal and ignore it. In this way, even if you log out of Linux, wget can continue downloading.
In addition, this signal is used to notify the daemon that is out of the relationship with the terminal to re-read the configuration file.
2) SIGINTThe interrupt signal is sent when you type the intr character (usually Ctrl-C) to notify the foreground process group to terminate the process.
3) sigquitSimilar to
); Sigaddset (SIGINT,sigs); Sigprocmask (Sig_block,sigs,0);//shielding the SIGINT signal so that it can no longer process the business//the interference process. for(i=0; i5; i++{printf ("process business ... \ n"); //Analog Business ProcessingSleep5) printf ("Process business end \ n"); Sigsuspend (sigmask);//handle the signal that is being queued, and when the signal is finished,//the Sigsuspend func
);}Child thread Exit sensible................return 0;}After the program is run, it is very strange that the program does not appear when the child thread exits when CTRL + C is pressed.After careful analysis, it is found that the problem lies in ignoring the characteristics of the multithreaded model under Linux.The threads under Linux are essentially lightweight processes (light weighted process) that generate the corresponding process control struc
sigaction to create another action, using the sigaction to install the signal. This overcomes the problem of the old signal call.#include int sigaction (int signum,const struct sigaction *act,struct sigaction*oldact));/* Set SIGINT */Action.sa_handler= Sig_handler;Sigemptyset (action.sa_mask);Sigaddset (action.sa_mask,sigterm);action.sa_flags= 0;/* Get last handler, if not ignore action, install signal */Sigaction (
function is blocked. The system returns an error by default and sets errno to Eintr. Set to auto restart hereAct.sa_flags|=Sa_restart; Act_dfl.sa_handler=SIG_DFL; Close (sp[0]); Close (sp[1]); if(0> sigaction (SIGTERM, AMP;ACT_DFL,0) ||0> sigaction (SIGINT, AMP;ACT_DFL,0) ||0> sigaction (SIGUSR1, AMP;ACT_DFL,0) ||0> sigaction (SIGUSR2, AMP;ACT_DFL,0) ||0> sigaction (SIGCHLD, AMP;ACT_DFL,0) ||0> sigaction (sigquit, act,0) {zlog (Zlog_syserror,"failed
^Csig_num: 2select: Interrupted system callhello world!hello world!
Because SIGINT has been registered through signal (2, handler);, it is clear that after pressing ctrl + c, the signal processing function handler will naturally capture this signal, therefore, ^ Csig_num: 2 is displayed.
The select function processes the interrupt signal. When an interruption signal is received,-1 is returned. Therefore, select: Interrupted system call select is displ
signal (). For example, when the user presses CTRL + C, the shell emits a SIGINT signal, and the default handler for SIGINT is the exit code that executes the process, but the following example sets the SIGINT response function to Int_handler.[Plain]View PlainCopyprint?
#include
#include
void Int_handler (int signum)
{
printf ("\nsigint signal h
https://blog.csdn.net/liuxingen/article/details/47057539
Linux System () and Popen () differences 1. System () and Popen () Introduction
In Linux we can execute a shell command through system (), and Popen () is also executing shell commands and communicating through pipes and shell commands.System (), Popen () to us to deal with the fork, exec, waitpid and so on a series of processing process, let us only
SVR4, which is ignored in 4.3BSD; Sigcont is continued when the process hangs, otherwise it is ignored and cannot be blockedWhen terminating the program, you cannot use Sigkill in a forced situation, because Sigkill does not process the sub-process, but handles itselfLinux supports POSIX standard signals and real-time signals. Below is a brief summary of the Linux signal, with detailed details to see Man 7 signal.The default action has the following
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.