当前位置:网站首页>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 .
边栏推荐
- Pytest (6) -fixture (Firmware)
- [flutter] example of asynchronous programming code between future and futurebuilder (futurebuilder constructor setting | handling flutter Chinese garbled | complete code example)
- Gbase 8C system table PG_ amproc
- Deep Reinforcement Learning for Intelligent Transportation Systems: A Survey 论文阅读笔记
- 超好用的日志库 logzero
- How to change the panet layer in yolov5 to bifpn
- SQL server queries the table structure of the specified table
- Tensorflow to pytorch notes; tf. gather_ Nd (x, y) to pytorch
- [fluent] JSON model conversion (JSON serialization tool | JSON manual serialization | writing dart model classes according to JSON | online automatic conversion of dart classes according to JSON)
- Informatics Olympiad one general question bank 1006 a+b questions
猜你喜欢

Pytest (6) -fixture (Firmware)

What does "where 1=1" mean

Check log4j problems using stain analysis

迅雷chrome扩展插件造成服务器返回的数据js解析页面数据异常

Matlab tips (24) RBF, GRNN, PNN neural network

【翻译】后台项目加入了CNCF孵化器

用docker 連接mysql的過程

I2C 子系统(四):I2C debug
![[fluent] JSON model conversion (JSON serialization tool | JSON manual serialization | writing dart model classes according to JSON | online automatic conversion of dart classes according to JSON)](/img/6a/ae44ddb090ce6373f04a550a15f973.jpg)
[fluent] JSON model conversion (JSON serialization tool | JSON manual serialization | writing dart model classes according to JSON | online automatic conversion of dart classes according to JSON)
![[shutter] banner carousel component (shutter_wiper plug-in | swiper component)](/img/a6/5c97ef3f34702b83ebf0511501d757.gif)
[shutter] banner carousel component (shutter_wiper plug-in | swiper component)
随机推荐
内存泄漏工具VLD安装及使用
Baidu map - surrounding search
random shuffle注意
C语言中左值和右值的区别
Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 2)
【翻译】后台项目加入了CNCF孵化器
【翻译】具有集中控制平面的现代应用负载平衡
Check log4j problems using stain analysis
js根据树结构查找某个节点的下面的所有父节点或者子节点
HW-初始准备
Gbase 8C trigger (III)
疫情当头,作为Leader如何进行代码版本和需求开发管控?| 社区征文
sql server 查询指定表的表结构
Build a private cloud disk cloudrev
MUX VLAN Foundation
Add MDF database file to SQL Server database, and the error is reported
Check log4j problems using stain analysis
leetcode540
where 1=1 是什么意思
处理数据集,使用LabelEncoder将所有id转换为从0开始