当前位置:网站首页>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 .
边栏推荐
- leetcode540
- [translation] flux is safe. Gain more confidence through fuzzy processing
- Tensorflow to pytorch notes; tf. gather_ Nd (x, y) to pytorch
- Unity3d human skin real time rendering real simulated human skin real time rendering "suggestions collection"
- sql server数据库添加 mdf数据库文件,遇到的报错
- The process of connecting MySQL with docker
- Add MDF database file to SQL Server database, and the error is reported
- Informatics Olympiad one general question bank 1006 a+b questions
- Gbase 8C system table PG_ auth_ members
- Super easy to use logzero
猜你喜欢

random shuffle注意

From C to capable -- use the pointer as a function parameter to find out whether the string is a palindrome character

Practice of traffic recording and playback in vivo

Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception

内存泄漏工具VLD安装及使用

Build a private cloud disk cloudrev

怎么将yolov5中的PANet层改为BiFPN

从C到Capable-----利用指针作为函数参数求字符串是否为回文字符

SQL statement

Random Shuffle attention
随机推荐
簡單理解svg
Gbase 8C function / stored procedure parameters (I)
Matlab tips (24) RBF, GRNN, PNN neural network
Interview stereotyped version
The left value and the right finger explain better
【Flutter】shared_ Preferences local storage (introduction | install the shared_preferences plug-in | use the shared_preferences process)
Practice of traffic recording and playback in vivo
Global and Chinese ammonium dimolybdate market in-depth analysis and prospect risk prediction report 2022 Edition
[shutter] setup of shutter development environment (supplement the latest information | the latest installation tutorial on August 25, 2021)
[Fuhan 6630 encodes and stores videos, and uses RTSP server and timestamp synchronization to realize VLC viewing videos]
Three.js本地环境搭建
定了,就选它
[fluent] listview list (map method description of list set | vertical list | horizontal list | code example)
The process of connecting MySQL with docker
Gbase 8C trigger (II)
【翻译】Flux安全。通过模糊处理获得更多信心
Kubernetes cluster log and efk architecture log scheme
Kubernetes family container housekeeper pod online Q & A?
二维格式数组格式索引下标连续问题导致 返回json 格式问题
Can netstat still play like this?