当前位置:网站首页>< job search> process and signal
< job search> process and signal
2022-07-02 03:18:00 【Have love】
One 、 process
process : An address space in which one or more threads are running and the system resources required by the threads .
ps command :process status Check the status of the running process
PID:2-32768 1 Generally, it is a special process Init Retain ,init Processes are responsible for managing other processes .
1、 Create child process
Replacement process impression :
exec Series of functions : Switch the execution of a program from one program to another , After the new program starts , The original program is no longer executed .
Copy process impression :
fork function : Create a new process . The new process executes the same code as the original process , But it has its own data space 、 Environment and file descriptors .
Possible reasons for the failure of creating sub process :
(1) When the number of child processes owned by the parent process exceeds the specified limit (CHILD_MAX), It may cause the creation of child processes to fail .errno:EAGAIN
(2) There is not enough space in the process table to create new forms or there is not enough virtual memory .errno:ENOMEM
2、 Waiting process
(1)pid_t wait(int *stat_loc) Call... That returns the child process PID, If stat_loc It's not a null pointer , The status information of the child process will be written to the location it points to .
State information :
WIFEXITED(stat_val) If the subprocess ends normally , Return non 0 value
WEXITSTATUS(stat_val) If WIFEXITED Not 0, Return the exit code of the child process
WIFSIGNALED(stat_val) If the child process is terminated by an uncapped signal , Return non 0 value
WTERMSIG(stat_val) If WIFSIGNALED Return non 0 value , Returns a signal code
WIFSTOPED(stat_val) If the subprocess terminates unexpectedly , It returns non 0 value
WSTOPSIG(stat_val) If WIFSTOPED Not 0, It returns a signal code
(2)pid_t waitpid(pid_t pid, int *stat_loc, int option) Wait for the specified process
3、 Zombie process
After the child process terminates , it The connection with the parent process will remain , Until the parent process also terminates normally or the negative process calls wait To terminate . therefore , Entries representing child processes in the process table will not be released immediately , Its exit code needs to be saved for the parent process in the future wait Use . At this time, it will become a zombie process or a dead process .
If the parent process terminates abnormally ,PID by 1 Of init The process will be the parent process .
Two 、 I / O redirection
ex:
cat file.txt // aaaaaa
./upper < file.txt //AAAAAA
3、 ... and 、 The signal
A signal is an event generated by the system in response to certain conditions , The signal is generated by certain error conditions . If the executing process receives the signal but does not arrange to capture it in advance , The process will terminate .
Common signals :
SIGABORT Process aborted
SIGINT Terminal interrupt (ctrl+c)
SIGKILL Terminate the process ( This signal cannot be captured or ignored )
SIGSEGV Invalid memory segment access
SIGSTOP Stop executing
SIGCHLD The child process has stopped or exited , By default , It is ignored
SIGCONT Continue the suspended process
If you want to send a signal to the process , But this process is not the current foreground process , Need to use Kill Command sending signal
1、 Sending signal
int kill(pid_t pid, int sig);
pase();// Suspend program execution , Until a signal appears .
2、 Signal processing functions
(1)void (*signal(int sig, void (*func)(int)))
sig: Processed signals func: The function called after receiving the signal
signal The function returns the function pointer of the signal processing function .
Signal processing functions are also available SIG_IGV( Ignore the signal )、SIG_DFL( Restore default behavior )
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
void A(int sig)
{
printf("I got signal %d\n",sig);
(void) signal(SIGINT, SIGDFL);// Restore default behavior
}
int main()
{
(void) signal(SIGINT, A);
while(1)
{
printf("hh\n");
sleep(1);
}
}Be careful , It is called in the signal processing function printf Functions are not safe .printf The internal implementation of needs to obtain the lock of the output first , Then modify the output , Finally, release the lock at the output . If the main program just gets the lock at the output , And the signal interrupts the main program , But the signal processing function is waiting for the main program to release the lock , This creates a deadlock .
(2) Robust signal interface
int sigaction(int sig, const struct sigaction *act, struct sigaction *oact);
sigaction Structure contains :
void (*) (int) sa_hander //function, SIG_IGN or SIG_DFL
sigset_t sa_mask // Signal set , Before calling the signal processing function , This signal set will be masked by the process
int sa_flags // The signal processing function is not reset by default , If it needs to be reset , It can be set to SA_RESETHAND
边栏推荐
- JIT deep analysis
- 在QML中加载不同字体
- On redis (II) -- cluster version
- Verilog state machine
- 浅谈线程池相关配置
- Missing numbers from 0 to n-1 (simple difficulty)
- Global and Chinese market of handheld ultrasonic scanners 2022-2028: Research Report on technology, participants, trends, market size and share
- Gradle 笔记
- aaaaaaaaaaaaa
- Mongodb non relational database
猜你喜欢

Verilog 状态机
![[staff] restore mark (Introduction to the use of restore mark | example analysis of Metaphone mark and restore mark)](/img/21/7bbf276b01f5a1056a22f5afc0af26.jpg)
[staff] restore mark (Introduction to the use of restore mark | example analysis of Metaphone mark and restore mark)

2022-2028 global encryption software industry research and trend analysis report

JS <2>

Verilog 过程连续赋值

小米青年工程师,本来只是去打个酱油

创业了...
![[staff] diacritical mark (ascending sign | descending sign B | double ascending sign x | double descending sign BB)](/img/96/8c4baa1dd8e35e2cab67461e7c447b.jpg)
[staff] diacritical mark (ascending sign | descending sign B | double ascending sign x | double descending sign BB)

SAML2.0 notes (I)
![[HCIA continuous update] overview of dynamic routing protocol](/img/03/83c883afb63b7c63f6879b5513bac3.jpg)
[HCIA continuous update] overview of dynamic routing protocol
随机推荐
Grpc快速实践
Named block Verilog
tarjan2
[HCIA continuous update] working principle of OSPF Protocol
Global and Chinese market of gynaecological health training manikin 2022-2028: Research Report on technology, participants, trends, market size and share
创业了...
C # joint Halcon's experience of breaking away from Halcon environment and various error reporting solutions
Verilog state machine
Redis cluster
Docker安装canal、mysql进行简单测试与实现redis和mysql缓存一致性
halcon图像矫正
What is the binding path of SAP ui5
数据传输中的成帧
C # joint halcon out of halcon Environment and various Error Reporting and Resolution Experiences
Gradle 笔记
A list of job levels and salaries in common Internet companies. Those who have conditions must enter big factories. The salary is really high
Find duplicates [Abstract binary / fast and slow pointer / binary enumeration]
The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added
Principle of computer composition - interview questions for postgraduate entrance examination (review outline, key points and reference)
QT environment generates dump to solve abnormal crash