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

相关推荐
夜月yeyue3 分钟前
Linux 内核驱动加载机制
linux·服务器·stm32·嵌入式硬件
_w_z_j_10 分钟前
爱丽丝的人偶
算法
好记忆不如烂笔头abc17 分钟前
Oracle19c rac两节点实例test,在节点1查看监听状态没有test1,但在节点2可以看到test2
运维·服务器
牢七23 分钟前
Linux新
linux
初学者_xuan29 分钟前
零基础新手小白快速了解掌握服务集群与自动化运维(十八)Ansible自动化模块--安装与入门
运维·自动化·ansible
风无雨1 小时前
windows docker 配置镜像
运维·docker·容器
老前端的功夫1 小时前
Vue2中key的深度解析:Diff算法的性能优化之道
前端·javascript·vue.js·算法·性能优化
C.咖.1 小时前
Linux环境下——Git 与 GitHub
linux·git·github·远程仓库
墨香幽梦客1 小时前
HTTPS/SSL证书全生命周期管理:从申请到续期的运维要点
运维·https·ssl
q***23571 小时前
使用 Nginx 搭建代理服务器(正向代理 HTTPS 网站)指南
运维·nginx·https