systems have two major types of signals
POSIX standard rule signal (regular signal 1-31 number)
Real-time signal (real-time signal 32-63)
Rule signal
Signal Number
name
Default Action
Description
1
SIGHUP
Terminate
Terminating a control terminal or process
2
SIGINT
Terminate
Terminal (CTRL-C) caused by the keyboard
times, you can receive how many times. Signal valueA reliable signal is located in the [Sigrtmin, Sigrtmax] zone.(2) Installation of the signalEarly Linux uses the system to call signal to install the signal#include void (*signal (int signum, void (*handler))) (int));The function has two parameters, Signum specifies the signal to be installed, handler the processing function of the specified signal.The return value of the function is a function pointer to the last installed handlerClassic Insta
Reference: Signal processing practice in shell scripts the signal trap function of the Linux shell you must know the details in Unix, each type of event that can occur is described by an independent signal, each of which is a small positive integer, such as:name value description sighup 1 Control terminal discovery suspended or control process death SIGINT 2 3 9 terminating signalUse: Kill-l to list suppor
Introduction to Linux programming-Signal Processing-general Linux technology-Linux programming and kernel information. For more information, see the following. Linux signal events
In this chapter, we will discuss the signal processing functions in Linux.
Signal processing functions in Linux:
Signal Generation
Signal Processing
Other Signal Functions
One instance
1. Signal Generation
The signal in Linux is similar to the INT in DOS or Windows. When a signal occurs
The signal we believe will be se
program continues after the signal processing function is executed. If the received signal terminates the program, sigsuspend will not return. If the received signal does not terminate the program, sigsuspend will return-1 and errno will be set to eintr. Note: If a signal is blocked by the process, it will not be passed to the process, but it will stay in the pending status. When the process unblocks the processing signal, the signal to be processed will be processed immediately. The following
These days, a network traffic collector
Program Basically changed. In the main function, after several sub-threads are started, the system goes to bed for 10 minutes and then cleans up the Sub-threads and exits. Now, if you want to change it to a subthread after it starts, the main thread enters infinite sleep until it receives the sigterm or SIGINT. The main program is as follows:
Other header files
# Include Int main (INT argc, char * argv []) {
//
Linux Signal Processing-general Linux technology-Linux programming and kernel information. The following is a detailed description. In this chapter, we will discuss the signal processing functions in Linux.
Signal processing functions in Linux:
Signal Generation
Signal Processing
Other Signal Functions
One instance
1. Signal Generation
The signals in Linux are similar to those in dos int or Windows. A trusted signal is sent to the corresponding process when a signal occurs. There are several sig
Turn from: http://blog.csdn.net/anxuegang/article/details/6636410
These days to a network flow collector program has been basically changed, the original in the main function in a few child threads started after sleeping 10 minutes after the start of cleaning child thread and exit. Now want to change to a child thread started after the main thread into infinite sleep, until received sigterm or SIGINT. The main program is as follows:Other header files
Http://blog.chinaunix.net/uid-9354-id-2425031.htmlSo I hope that the same way to deal with the multiple occurrences of the signal, it is best to use sigaction. The signal only appears and is processed once, can be used signal.Each time the signal function sets a specific signal processing function (non-sig_ign), it can only take effect once, and each time the process responds to processing the signal, the signal processing function is reverted to the default processing. So if you want to process
/** Title: * Please write a program to set the SIGINT and sigquit signals, * and in the program to implement the operation of reading information from the file, * and ensure that the file is read and only in the process of reading the file will not be sent by the SIGINT and sigquit signal interrupted. * HINT: block the signal before the file is read and unblock the file after it is read. * */#include#includ
over to process 1, and process 1 becomes the stepfather of these sub-processes. Process 1 will handle the resources of these processes well. When they are finished, process 1 will automatically recycle the resources. Therefore, another temporary way to handle zombie processes is to close their parent processes.
4. Signal
Generally, the multi-process is finished, but the signal is indeed a very important thing in the system. A signal is a signal lamp. When a signal lamp is lit, the program will
-- SIGINT ");Break;Case 3:Printf ("Get a signal -- SIGQUIT ");Break;}Return;}
Int main (){Printf ("process id is % d", getpid ());Signal (SIGHUP, sigroutine); // * set the processing method of the three signals belowSignal (SIGINT, sigroutine );Signal (SIGQUIT, sigroutine );For (;;);}
The signal SIGINT is triggered by pressing Ctrl-C, and the signal SIGQUIT is t
");}Void user_func (int signum){Printf ("receive signal % d/N", SIGNUM );}
$ CC-o sus. c$./SUS [1] 997
Another Console# Kill-s 42 PID
Look...
$Now begin to get pending mask and unblock sigrtmin + 10
Signal sigrtmin + 10 is pendingReceive signal 42Signal unblocked, OK ......
[1] + exit 31./d$
Example 3: Signal
Code
# Include # Include # Include # Define damoVoid user_func (INT No){Switch (NO){Case 1:Printf ("Get sighup./N ");Break;Case 2:Printf ("Get SIGINT
to the online manual to use this format.In the call, the SIGNUM parameter indicates the signal to set the processing method. The second handler parameter is a processing function, orSig_ign: Ignore the signal specified by the SIGNUM parameter.Sig_dfl: the signal processing method specified by the recovery parameter SIGNUM is the default value.The integer parameter passed to the signal processing routine is the signal value, so that a signal processing routine can process multiple signals. When
long time, you may press Ctrl + C to close the program. In fact, the keyboard sends an interrupt signal to the program: SIGINT. Sometimes the process will execute the kill [PID] command if it loses response. Without any other parameters, the program will receive a SIGTERM signal. When the program receives the above two signals, the execution ends by default. Is it possible to change this default behavior? Yes!
4.1. Registration Signal
A person is a l
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 return value).2. System (), Popen () source codeFirst, let's look at the differences between
Pause function:
function: Let the process pause until the signal appears#include Intpause ();Function Description: Pause () pauses the current process (goes to sleep) until the signal (signal) is interrupted.Return value: Returns only-1.#include #includevoid deal () { printf ("signal interference! \ n ");} void Main () { printf ("Process Execution! \ n "); Signal (sigint,deal); Pause (); printf ("The process is over!" \ n ");}Des
process multiple signals. The system call signal return value is the specified signal Signum the previous processing routine or error when the error code Sig_err is returned. Let's look at a simple example:#include #include #include void sigroutine (int dunno) {/* signal processing routine where dunno will get the value of the signal */switch (dunno) {Case 1:printf ("Get a signal--SIGHUP");Break ;Case 2:printf ("Get a signal--SIGINT");Break ;Case 3:p
specified signal Signum the previous processing routine or error when the error code Sig_err is returned. Let's look at a simple example:#include #include #include void sigroutine (int dunno) {/* signal processing routine where dunno will get the value of the signal */switch (dunno) {Case 1:printf ("Get a signal--SIGHUP");Break ;Case 2:printf ("Get a signal--SIGINT");Break ;Case 3:printf ("Get a signal--sigquit");Break ;}return;}int main () {printf (
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.