Linux--system函数

system函数相当于封装后的exec

c 复制代码
#include <stdlib.h>

int system(const char *command);

system()函数的返回值如下:

成功:则返回进程状态值;当sh不执行时,返回127;

失败:返回-1;

c 复制代码
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

int main()
{
	pid_t pid;
	int data = 10;
	
	while(1){
		printf("please input a data:\n");
		scanf("%d",&data);
		if(data == 1){
			int fdSrc;
			pid = fork();
			if(pid > 0){
				wait(NULL);
			}
			if(pid == 0){
				//execl("./changeData","changeData","config.txt",NULL);				
			system("./changeData config.txt");
			}
		}
		else{
			printf("wait ,do nothing!\n");
		}
	}
	
	return 0;
}

linux system函数详解 https://www.cnblogs.com/leijiangtao/p/4051387.html

相关推荐
RisunJan1 天前
Linux命令-lvextend(扩展逻辑卷空间)
linux·运维·服务器
tankeven1 天前
HJ92 在字符串中找出连续最长的数字串
c++·算法
艾莉丝努力练剑1 天前
【Linux:文件】进程间通信
linux·运维·服务器·c语言·网络·c++·人工智能
小雨中_1 天前
3.1 RLHF:基于人类反馈的强化学习
人工智能·python·深度学习·算法·动态规划
The森1 天前
Linux IO模型纵深解析:文章索引
linux·运维·服务器
relis1 天前
从 dma-buf 到 tensor parallel:跨越领域的零拷贝模式
算法
心本无晴.1 天前
LangGraph 进阶指南:从状态机到生产级多智能体架构的全面进化
linux·windows·microsoft
一条大祥脚1 天前
Manacher/马拉车算法
算法
小李独爱秋1 天前
模拟面试:不能关机的情况下 , 如果挂载目录卸载不掉应该怎么办?
linux·运维·面试·职场和发展·操作系统·文件系统