当前位置:网站首页>< 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
边栏推荐
- verilog REG 寄存器、向量、整数、实数、时间寄存器
- 3124. Word list
- MongoDB非關系型數據庫
- [staff] diacritical mark (ascending sign | descending sign B | double ascending sign x | double descending sign BB)
- 4. Find the median of two positive arrays
- Global and Chinese markets for welding equipment and consumables 2022-2028: Research Report on technology, participants, trends, market size and share
- 寻找重复数[抽象二分/快慢指针/二进制枚举]
- Stdref and stdcref
- Verilog parallel block implementation
- aaaaaaaaaaaaa
猜你喜欢

How to create an instance of the control defined in SAP ui5 XML view at runtime?

2022-2028 global soft capsule manufacturing machine industry research and trend analysis report

Verilog state machine
![Find duplicates [Abstract binary / fast and slow pointer / binary enumeration]](/img/9b/3c001c3b86ca3f8622daa7f7687cdb.png)
Find duplicates [Abstract binary / fast and slow pointer / binary enumeration]

Addition without addition, subtraction, multiplication and division (simple difficulty)

Verilog 过程赋值 区别 详解

Halcon image rectification

使用 useDeferredValue 进行异步渲染

MSI announced that its motherboard products will cancel all paper accessories

Verilog avoid latch
随机推荐
How to develop digital collections? How to develop your own digital collections
表单自定义校验规则
Competition and adventure burr
/silicosis/geo/GSE184854_ scRNA-seq_ mouse_ lung_ ccr2/GSE184854_ RAW/GSM5598265_ matrix_ inflection_ demult
KL divergence is a valuable article
Verilog wire type
JS introduction < 1 >
Cache processing scheme in high concurrency scenario
Qualcomm platform wifi-- WPA_ supplicant issue
32, 64, 128 bit system
跟着CTF-wiki学pwn——ret2shellcode
[JS reverse series] analysis of a customs publicity platform
Calculation of page table size of level 2, level 3 and level 4 in protection mode (4k=4*2^10)
Verilog avoid latch
[HCIA continuous update] overview of dynamic routing protocol
数据传输中的成帧
Mathematical calculation in real mode addressing
Grpc快速实践
About DNS
2022-2028 global deep sea generator controller industry research and trend analysis report