当前位置:网站首页>< 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
边栏推荐
- 跟着CTF-wiki学pwn——ret2shellcode
- The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added
- /silicosis/geo/GSE184854_scRNA-seq_mouse_lung_ccr2/GSE184854_RAW/GSM5598265_matrix_inflection_demult
- Render header usage of El table
- verilog REG 寄存器、向量、整数、实数、时间寄存器
- Common means of modeling: aggregation
- Qualcomm platform WiFi -- Native crash caused by WiFi
- ORA-01547、ORA-01194、ORA-01110
- Pointer array & array pointer
- Intersection of Venn graph
猜你喜欢

Learn PWN from CTF wiki - ret2shellcode
![[JVM] detailed description of the process of creating objects](/img/6e/0803b6b63c48337985faae8d5cbe1a.png)
[JVM] detailed description of the process of creating objects

Verilog 过程连续赋值

MMSegmentation系列之训练与推理自己的数据集(三)

Force deduction daily question 540 A single element in an ordered array

West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials

MSI announced that its motherboard products will cancel all paper accessories

Retrofit's callback hell is really vulnerable in kotlin synergy mode

halcon图像矫正

跟着CTF-wiki学pwn——ret2shellcode
随机推荐
小米青年工程师,本来只是去打个酱油
[C Advanced] brother Peng takes you to play with strings and memory functions
Grpc快速实践
2022-2028 global nano abrasive industry research and trend analysis report
3048. Number of words
C # joint Halcon's experience of breaking away from Halcon environment and various error reporting solutions
Design details of SAP e-commerce cloud footernavigationcomponent
Xiaomi, a young engineer, was just going to make soy sauce
C#联合halcon脱离halcon环境以及各种报错解决经历
A list of job levels and salaries in common Internet companies. Those who have conditions must enter big factories. The salary is really high
Mongodb non relational database
【JVM】创建对象的流程详解
Baohong industry | what misunderstandings should we pay attention to when diversifying investment
3124. Word list
寻找重复数[抽象二分/快慢指针/二进制枚举]
venn图取交集
Continuous assignment of Verilog procedure
Detailed explanation of the difference between Verilog process assignment
Mathematical calculation in real mode addressing
Baohong industry | 6 financial management models at different stages of life