code for linux Process Communication. The operating system is redhat9.0, the editor is vi, and the compiler uses gcc. All the following implementation code has passed the test and runs correctly. 1. Low-level communication-signal Communication Signal. c# Include # Include # Include /* Execute the pre-defined action function after the signal sig is captured */Void sig_alarm (int sig){Printf ("--- the signal encoded Ed is % d./n", sig );Signal (SIGINT
Linux system programming (23)-signal blocking, linux23
The processing action of the actually executed signal is called the Delivery, the State between the signal generation and the Delivery, and the Pending ). A process can Block a signal. When a blocked signal is generated, it remains in the pending state until the process unblocks the signal. Note that blocking and ignoring are different. As long as the signal is blocked, it will not be delivered. Ignoring is an optional action after delivery
signal, do not display the message (and implicitly do not stop running the program)L pass sends the signal to the program, allowing your program to process it, stop running, or take other actions.L nopass stops running the program, but do not send signals to the program.For example, assume that you intercept the sigpipe signal to prevent the program being debugged from receiving the signal. Once the signal arrives, the program is required to stop and notify you. To complete this task, use the f
status );
Void _ exit (INT status );
# Include
Void _ exit (Status );
None of the call _ exit and _ exit will call the termination program.
No exception will be terminated.
Sighup
SIGINT terminates process interruption
Sigquit creates a core file to terminate the process and generates a Core File
Invalid Command for creating core file in sigill
Sigtrap creates core file tracking self-traps
Sigbus Core File bus creation err
The concept of a signal
Signal (signal)--the way communication between processes is a software interrupt. Once a process receives a signal, it interrupts the original program execution process to process the signal.
Several common signals:
SIGINT terminating process interrupt process (CONTROL+C)
Sigquit Exit Process
SIGTERM terminating process software termination signal (default signal)
SIGKILL Terminate process Kill process
SIGALRM Alarm Cloc
In 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-l
root@server:~# kill-l
1) SIGHUP 2) SIGINT 3) Sigquit 4) Sigill 5) SIGTRAP 6) SIGABRT 7) Sigbus 8) SIGFPE 9) SIGKILL) SIGUSR111) SIGSEGV) (SIG
is $? "# The reference of the return valecho" the current directory is "'pwd' #-eq = str = 5str2 = 5if [" $ {str} "-eq" ${str2} "]; then echo "$ str equal $ str2" else echo "no equal" fi #-ge> = str = 5str2 = 10if ["$ str2"-ge "$ str"]; then echo "$ str2 >=$ str" else echo "no ge" fi #-gt >;- le 0. /test_dir is dir. /test_dir is not file5 is 5we will use function add 3 + 8 + 10the sum val is 216 seconds u Ntil system failure, you can use CTRL + C ~ 5 seconds until system failure, you can use C
output is not the same, seeThis is the effect of Webstrom in the command line is not visible
PROCESS.CWD (): Represents the absolute path of the current file, this and __dirname is a different __dirname output is through node execution of the JS file is located in the absolute path, see it can understand,
Process.on ()
Process.on (' Exit ', function () {}) indicates that it will be triggered when the program exits.
process.on(‘exit‘,function(){ console.log("pro
"); - } - - //according to the command to do the corresponding processing in Switch($command) - { to //Start Workerman + Case' Start ': - if($command 2= = = '-d ') the { *Worker::$daemonize=true; $ }Panax Notoginseng Break; - //show Workerman Run status the Case' Status ': + Exit(0); A //Restart Workerman the
;Act.sa_handler = handler;act.sa_flags = 0;Sigemptyset (act.sa_mask);Test Signal Installation functionSigaction (SIGINT, act, NULL);Analog signal functionMy_signal (SIGINT, handler);for (;;){Pause ();}return 0;}
Experiment 2: Test the function of the third parameter of sigaction structure sigset_t sa_mask/*struct Sigaction {void (*sa_handler) (int);void (*sa_sigaction) (int, siginfo_t *, void *)
To execute a command every minute in the liunx system, the most common method is crontab. if you do not want to use crontab, the most common way to execute a command every minute in the liunx system is to use a timer. if you do not want to use crontab, after being instructed by my colleagues, I could use a timer in the program to implement this function. so I began to explore and found that I needed some signal knowledge...
Check what signals your linux supports: kill-l.
root@server:~# kill -l
This is a creation in
Article, where the information may have evolved or changed. # # # # # # # # # # # # # # # # The same code is different from CentOS 6.5 under MacOS 13.3 # # # # # # # # problem code ' go//This code is a MySQL Client, the incoming host, user, port and other parameters to do processing//here a co-monitoring singnal passed to the child process, to ensure that MySQL Clinet can monitor Singalgo func () {for {sig: = sigint://MySQL clinet will be stdin monitoring
required to stop and notify you. To complete this task, you can use the following command: (gdb) handle SIGPIPE stop print. Note that UNIX signal names always use uppercase letters! You can use the signal number to replace the signal name. if your program wants to perform any signal processing operations, you need to be able to test its signal processing program, A simple method is required to send signals to the program, which is the task of the signal Command. The parameter of this command is
Child process started successfully, parent exiting 5. Safely stop the Mongod process The most basic method is to send SIGINT or sigterm signals to the MongoDB server. If the front-end process runs on the terminal, the direct ctrl-c abort, otherwise, use kill to send the signal to abort. Kill-2 Mongodpid (SIGINT) Kill Mongodpid (SIGTERM) Mongod receive SIGINT or
/*Unsafe:this Handler uses Non-async-signal-safe functions (printf (), Eixt ())*/8 9 if(sig = =SIGINT) {Tencount++; Oneprintf"caught SIGINT (%d) \ n", count); A return;/*Resume execution at point of interruption*/ - } - the /*must be sigquit-print a message and terminate the process*/ - -printf"caught Sigquit-that ' s all forks!\n"); - exit (exit_success); + } - + intMainintargcC
There was a previous article that described some contrasts:Http://www.cnblogs.com/charlesblc/p/6078029.htmlHere's a bit more about code and application.Look at the two sides of the HelloWorld basic understanding of the approximate.Libevent's Hello World#include #includevoidSIGNAL_CB (intFd ShortEventvoid*Arg) {Event_base*base = (event_base*) Arg; Timeval Delay= {2, 0}; printf ("Caught an interrupt signal, exit in 2 sec ... \ n "); Event_base_loopexit (Base,delay);}voidTIMEOUT_CB (intFd ShortEven
Exiting a running program can be rough kill-9 $PID, but this will disrupt the integrity of the business, it is possible that one is executing in the middle of the logic, resulting in abnormal garbage data.This article summarizes in go language, how can gracefully exit the network application, involves the knowledge including: Signal,channel,waitgroup and so on.From here: Https://gobyexample.com/channel-synchronization can simply learn how to use the channel in go to achieve goroutines synchroniz
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.