当前位置:网站首页>Segmentation fault occurs during VFORK execution
Segmentation fault occurs during VFORK execution
2022-07-03 02:49:00 【Black Whirlwind big Li Kui】
1. First of all, understand vfork What is it for ?
Linux Type... On the command line man vfork enter
Look at the instructions in the red box , Which translates to vfork - Create a child process and block the parent process ,block n. block v. Blocking .
The red box below appears at the bottom of the manual BUGS, explain vfork By BUG Of . Translated into The details of signal processing are fuzzy , There are differences between systems ( Different ).BSD The man page indicates :“ To avoid deadlock ,vfork() Never send SIGTTOU( The background process attempts to write a signal from the control terminal ) or SIGTTIN( The background process attempts to read a signal from the control terminal ) The signal ; contrary , Allow output or ioctl, And the input will cause the file end instruction .”
2. appear Segmentation fault The error code is as follows :
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
pid_t pid=vfork();
if(pid==-1)
{
printf("Create process is fault.\n");
}
if(pid==0)
{
printf("Child process %d is running.\n",getpid());
}
else
{
printf("Parent process %d is running.\n",getpid());
}
return 0;
}
The results of the program are as follows :
As can be seen from the program results ,vfork Execute subprocess first , Then execute the parent process , But this code appears Segmentation fault.
3. Use strace Command trace this program
stay Linux The input terminal strace -f -s 65500 -i -T ./vfork
From the tracking results, it is only called once exit_group(0), In the right case, it should be executed twice return 0;
How to modify a program ?
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
int main()
{
pid_t pid=vfork();
if(pid==-1)
{
printf("Create process is fault.\n");
}
if(pid==0)
{
printf("Child process %d is running.\n",getpid());
}
else
{
printf("Parent process %d is running.\n",getpid());
}
exit(0);// take return 0; To replace the ,exit() Function in stdlib.h Header file
}
The execution result is :
And it turns out that Segmentation fault The mistake disappeared .
边栏推荐
- As a leader, how to control the code version and demand development when the epidemic comes| Community essay solicitation
- [hcia]no.15 communication between VLANs
- [Hcia]No.15 Vlan间通信
- [leectode 2022.2.15] lucky numbers in the matrix
- [translation] flux is safe. Gain more confidence through fuzzy processing
- 你真的懂继电器吗?
- MATLAB小技巧(24)RBF,GRNN,PNN-神经网络
- Kubernetes family container housekeeper pod online Q & A?
- 【翻译】Flux安全。通过模糊处理获得更多信心
- What does "where 1=1" mean
猜你喜欢
Baidu map - surrounding search
《MATLAB 神经网络43个案例分析》:第43章 神经网络高效编程技巧——基于MATLAB R2012b新版本特性的探讨
面试项目技术栈总结
Didi programmers are despised by relatives: an annual salary of 800000 is not as good as two teachers
Pytest (6) -fixture (Firmware)
你真的懂继电器吗?
[flutter] example of asynchronous programming code between future and futurebuilder (futurebuilder constructor setting | handling flutter Chinese garbled | complete code example)
【翻译】后台项目加入了CNCF孵化器
Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)
SQL statement
随机推荐
HTB-Devel
Super easy to use logzero
MUX VLAN Foundation
[shutter] banner carousel component (shutter_wiper plug-in | swiper component)
js根据树结构查找某个节点的下面的所有父节点或者子节点
sql server 查询指定表的表结构
Kubernetes cluster log and efk architecture log scheme
Basic operation of binary tree (C language version)
SQL Server Query spécifie la structure de la table
Tensorflow to pytorch notes; tf. gather_ Nd (x, y) to pytorch
Random shuffle note
Baidu map - surrounding search
[C语言]给账号密码进行MD5加密
vfork执行时出现Segmentation fault
Unity3d human skin real time rendering real simulated human skin real time rendering "suggestions collection"
Gbase 8C system table PG_ am
Serious security vulnerabilities reported by moxa mxview network management software
I2C 子系统(四):I2C debug
Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 2)
The left value and the right finger explain better