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

相关推荐
s09071361 分钟前
连通域标记:从原理到数学公式全解析
图像处理·算法·fpga开发·连通域标记
QUST-Learn3D3 分钟前
geometry4Sharp Ray-Mesh求交 判断点是否在几何体内部
服务器·前端·数据库
凯子坚持 c4 分钟前
0基础如何搭建个人博客?GMSSH可视化运维工具配合WordPress部署全流程教学
运维·docker·gmssh
触想工业平板电脑一体机4 分钟前
【触想智能】工业视觉设备与工控一体机进行配套需要注意的五大事项
android·大数据·运维·电脑·智能电视
运维行者_6 分钟前
跨境企业 OPM:多币种订单与物流同步管理,依靠网络自动化与 snmp 软件
大数据·运维·网络·数据库·postgresql·跨境企业
@小码农6 分钟前
6547网:202512 GESP认证 C++编程 一级真题题库(附答案)
java·c++·算法
oMcLin7 分钟前
如何在Ubuntu 20.04上通过配置ZFS存储池,提升高性能存储系统的可靠性与扩展性
linux·运维·ubuntu
独自破碎E10 分钟前
使用Linux的top命令进行性能监控的步骤?
linux
Ha_To13 分钟前
2026.1.6 Windows磁盘相关
linux·运维·服务器
牛奶咖啡1313 分钟前
shell脚本编程(一)
linux·shell·shell脚本·shell脚本解析·grep命令语法·grep选项详解·正则表达式解析