当前位置:网站首页>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 .
边栏推荐
- Tensorflow to pytorch notes; tf. gather_ Nd (x, y) to pytorch
- 用docker 連接mysql的過程
- tensorflow转pytorch笔记;tf.gather_nd(x,y)转pytorch
- Can netstat still play like this?
- 当lambda没有输入时,是何含义?
- Choose it when you decide
- yii2 中andWhere多个or查询 orm条件
- Why choose a frame? What frame to choose
- 搭建私有云盘 cloudreve
- 处理数据集,使用LabelEncoder将所有id转换为从0开始
猜你喜欢
I2C 子系统(二):I3C spec
Deep Reinforcement Learning for Intelligent Transportation Systems: A Survey 论文阅读笔记
Three.js本地环境搭建
MATLAB小技巧(24)RBF,GRNN,PNN-神经网络
Three. JS local environment setup
Can netstat still play like this?
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]
Choose it when you decide
Add MDF database file to SQL Server database, and the error is reported
The process of connecting MySQL with docker
随机推荐
Kubernetes family container housekeeper pod online Q & A?
Cron表达式介绍
Error invalid bound statement (not found): com ruoyi. stock. mapper. StockDetailMapper. XXXX solution
Two dimensional format array format index subscript continuity problem leads to return JSON format problem
【富瀚6630编码存录像,用rtsp服务器及时间戳同步实现vlc观看录像】
Classes and objects - initialization and cleanup of objects - constructor call rules
Your family must be very poor if you fight like this!
超好用的日志库 logzero
What does "where 1=1" mean
Pytest (6) -fixture (Firmware)
JS finds all the parent nodes or child nodes under a node according to the tree structure
[shutter] banner carousel component (shutter_wiper plug-in | swiper component)
ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc
【翻译】Flux安全。通过模糊处理获得更多信心
How to change the panet layer in yolov5 to bifpn
【Flutter】shared_ Preferences local storage (introduction | install the shared_preferences plug-in | use the shared_preferences process)
where 1=1 是什么意思
Check log4j problems using stain analysis
Random shuffle note
你真的懂继电器吗?