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

相关推荐
xsc-xyc5 分钟前
虚拟机Ubuntu重启发现找不到共享文件夹
服务器·ubuntu
skywalk81635 分钟前
Ubuntu24.04启动后显示:推荐安装输入法面板这个Gnome Shell,否则可能无法看到输入法窗口 extension/261/kimpanel
linux·运维·服务器
网硕互联的小客服16 分钟前
CentOS8 Stream 网卡配置及重启
linux·运维·服务器
monster_风铃38 分钟前
华为ACL实验配置
运维·服务器
www.0240 分钟前
在ubuntu服务器下安装cuda和cudnn(笔记)
linux·ubuntu·cuda·cudnn·服务器环境
早睡冠军候选人1 小时前
Linux高级逻辑卷配置
linux·云原生
DXY7981 小时前
Ext系列文件系统
运维·linix
青草地溪水旁2 小时前
Linux 信号处理标志sa_flags详解
linux·信号处理
ALLSectorSorft2 小时前
定制客车系统票务管理系统功能设计
linux·服务器·前端·数据库·apache