调用exec()后进程在何处终止

博客探讨了在调用exec()函数后,进程如何以及在哪里终止。内容深入解析了exec()在进程生命周期中的作用,以及它如何影响进程的执行路径。
摘要由CSDN通过智能技术生成

调用exec()后进程在何处终止

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
int main()
{
	int a = 1;
	int pid;
	char buff[] = "before fork";
	if(write(1, buff, sizeof(buff) - 1) != (sizeof(buff) - 1))
	{
		perror("write error");
		exit(0);
	}/* fork之前的代码不会在子进程中执行 */
	if( (pid = fork()) == -1 )
	{
		perror("fork error");
		exit(1);
	}
	else if(pid == 0)
	{
		if( execlp( "./write1", "write1", (char *)0 ) == -1 )
		{
			perror("execlp error");
			exit(1);
		}/* exec函数执行的程序替换了所在进程的进程空间,执行完后进程就终止了了,所以下面两行代码不会执行 */
		/*********************进程在此处终止*****************************/
		a++;	/* 不会执行 */
		printf("%d", a);	/* 不会执行 */
	}
	if( execlp( "./write1", "write1", (char *)0 ) == -1 )
	{
		perror("execlp error");
		exit(1);
	}
	/*********************进程
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值