Linux exit()/_exit()


当我们需要结束一个进程的时候,我们可以使用exit()函数或_exit()函数来终止该进程。当程序运行到exit()函数或_exit()函数时,进程会无条件停止剩下的所有操作,并进行清理工作,最终将进程停止。

exit()

所需头文件:
#include<stdlib.h>

函数原型:
void exit(int status)

函数参数:
status   表示让进程结束时的状态(会由主进程的wait();负责接收这个返回值,也可以不接收,类似函数的返回值),默认使用0表示正常结束

返回值:无

_exit()

所需头文件:#include<unistd.h>

函数原型:
void _exit(int status)

函数参数:
status    同exit()函数

返回值:无

exit()和_exit()的区别

exit()函数与_exit()函数用法类似,但是这两个函数还是有很大的区别的。

_exit()函数直接使进程停止运行,当调用_exit()函数时,内核会清除该进程的内存空间,并清除其在内核中的各种数据。

exit()函数则在_exit()函数的基础上进行了升级,在退出进程之间增加了若干工序。exit()函数在终止进程之前会检测进程打开了哪些文件,并将缓冲区内容写回文件。

因此,exit()函数与_exit()函数最主要的区别就在于是否会将缓冲区数据保留并写回。_exit()函数不会保留缓冲区数据,直接将缓冲区数据丢弃,直接终止进程运行;而exit()函数会将缓冲区内数据写回,待缓冲区清空后再终止进程运行。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WARNING: /home/xyc/work/petalinux_prj/20230518/zynq_petalinux/build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.10+git999-r0/temp/run.do_kernel_configme.126308:414 exit 1 from 'exit 1' WARNING: Backtrace (BB generated script): #1: bbfatal, /home/xyc/work/petalinux_prj/20230518/zynq_petalinux/build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.10+git999-r0/temp/run.do_kernel_configme.126308, line 414 #2: do_kernel_metadata, /home/xyc/work/petalinux_prj/20230518/zynq_petalinux/build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.10+git999-r0/temp/run.do_kernel_configme.126308, line 251 #3: do_kernel_configme, /home/xyc/work/petalinux_prj/20230518/zynq_petalinux/build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.10+git999-r0/temp/run.do_kernel_configme.126308, line 152 #4: main, /home/xyc/work/petalinux_prj/20230518/zynq_petalinux/build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.10+git999-r0/temp/run.do_kernel_configme.126308, line 459 Backtrace (metadata-relative locations): #1: bbfatal, /home/xyc/work/petalinux_prj/20230518/zynq_petalinux/components/yocto/layers/core/meta/classes/logging.bbclass, line 60 #2: do_kernel_metadata, /home/xyc/work/petalinux_prj/20230518/zynq_petalinux/components/yocto/layers/core/meta/classes/kernel-yocto.bbclass, line 159 #3: do_kernel_configme, /home/xyc/work/petalinux_prj/20230518/zynq_petalinux/components/yocto/layers/core/meta/classes/kernel-yocto.bbclass, line 395 ERROR: Logfile of failure stored in: /home/xyc/work/petalinux_prj/20230518/zynq_petalinux/build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.10+git999-r0/temp/log.do_kernel_configme.126308 NOTE: recipe linux-xlnx-5.10+git999-r0: task do_kernel_configme: Failed ERROR: Task (/home/xyc/work/petalinux_prj/20230518/zynq_petalinux/components/yocto/layers/meta-xilinx/meta-xilinx-bsp/recipes-kernel/linux/linux-xlnx_2021.1.bb:do_kernel_configme) failed with exit code '1' NOTE: recipe libgcc-initial-10.2.0-r0: task do_configure: Succeeded NOTE: Tasks Summary: Attempted 545 tasks of which 0 didn't need to be rerun and 1 failed. ERROR: bitbake failed to configure u-boot ERROR: Failed to config u-boot. Check the /home/xyc/work/petalinux_prj/20230518/zynq_petalinux/build/config.log file for more details...
05-19

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值