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

相关推荐
AndrewHZ30 分钟前
【图像处理基石】什么是油画感?
图像处理·人工智能·算法·图像压缩·视频处理·超分辨率·去噪算法
.格子衫.31 分钟前
015枚举之滑动窗口——算法备赛
数据结构·算法
J先生x2 小时前
【IP101】图像处理进阶:从直方图均衡化到伽马变换,全面掌握图像增强技术
图像处理·人工智能·学习·算法·计算机视觉
π大星星️2 小时前
基于LNMP架构的个人博客系统部署
服务器·架构
爱coding的橙子4 小时前
每日算法刷题 Day3 5.11:leetcode数组2道题,用时1h(有点慢)
算法·leetcode
孙克旭_5 小时前
PXE_Kickstart_无人值守自动化安装系统
linux·运维·自动化
皓月盈江6 小时前
Linux电脑本机使用小皮面板集成环境开发调试WEB项目
linux·php·web开发·phpstudy·小皮面板·集成环境·www.xp.cn
深井冰水6 小时前
mac M2能安装的虚拟机和linux系统系统
linux·macos
leoufung6 小时前
内核内存锁定机制与用户空间内存锁定的交互分析
linux·kernel
π大星星️7 小时前
HAProxy + Keepalived + Nginx 高可用负载均衡系统
运维·nginx·负载均衡