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

相关推荐
白緢7 分钟前
嵌入式 Linux + 内核开发高频问题及排查
java·linux·运维
学编程就要猛8 分钟前
JavaEE初阶:网络编程
运维·服务器·网络
Proxy_ZZ011 分钟前
打造自己的信道编码工具箱——Turbo、LDPC、极化码三合一
c语言·算法·信息与通信
wayz1113 分钟前
21天机器学习核心算法学习计划(量化方向)
学习·算法·机器学习
hughnz13 分钟前
钻井自动化案例研究
运维·自动化
穿条秋裤到处跑14 分钟前
每日一道leetcode(2026.04.09):区间乘法查询后的异或 II
算法·leetcode
ILL11IIL17 分钟前
Docker容器技术
运维·docker·容器
蜡笔小新..19 分钟前
Linux下Matplotlib使用Times New Roman字体的解决方案
linux·运维·matplotlib
超级大只老咪21 分钟前
一维度前缀和解题通用模板(java)
java·开发语言·算法
飞yu流星21 分钟前
文件压缩、文本内容、文本编辑
运维·服务器