Linux system programming 52 signals-real-time signals

Standard signal characteristics:

1 标准信号会丢失
2 标准信号 没有一个严格的响应顺序要求,未定义行为。

There are two signals with undefined behavior in the standard signals, which are left for us to use: SIGUSR1, SIGUSR2

Real-time signals are used to solve the deficiencies of standard signals:

1 实时信号不会丢失
2 实时信号响应有顺序要求

Real-time signal experiment:

kill -l view signal, select 40) SIGRTMIN+6 signal

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

#define MYRTSIGNAL (SIGRTMIN+6)

void sig_handler(int s)
{
	write(1,"!",1);
}

int main()
{
	int i,j;
	sigset_t set,saveset,oset;

	signal(MYRTSIGNAL,sig_handler);
	
	sigemptyset(&set); 
	sigaddset(&set,MYRTSIGNAL); 

	
	sigprocmask(SIG_UNBLOCK,&set,&saveset);

	sigprocmask(SIG_BLOCK,&set,&oset); 
	for(j=0;j < 1000;j++)
	{

		
		for(i=0 ; i<5 ; i++) 
		{
			write(1,"*",1);
			sleep(1);
		}	
		write(1,"\n",1);
		
		sigsuspend(&oset);
	}

	sigprocmask(SIG_SETMASK,&saveset,NULL);

	exit(0);
}

Insert picture description here

It is found that the real-time signal will not be lost, and the signal is sent three times in a row. If it is a standard signal, it will only respond once, and the real-time signal will respond three times.

mhr@ubuntu:~/Desktop/xitongbiancheng/parallel/signal/test$ 
mhr@ubuntu:~/Desktop/xitongbiancheng/parallel/signal/test$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 3749
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 3749
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
mhr@ubuntu:~/Desktop/xitongbiancheng/parallel/signal/test$ 

The real-time signal can queue up to 3749
pending signals (-i) 3749

Guess you like

Origin blog.csdn.net/LinuxArmbiggod/article/details/114148180