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

相关推荐
空灵之海18 分钟前
Ubuntu Server 22.04.5系统安装教程
linux·运维·ubuntu
gamers39 分钟前
rock linux 9 安装mysql 5.7.44
linux·mysql·adb
arbboter1 小时前
【自动化】深入浅出UIAutomationClient:C#桌面自动化实战指南
运维·c#·自动化·inspect·uiautomation·uia·桌面自动化
听情歌落俗1 小时前
MATLAB3-1变量-台大郭彦甫
开发语言·笔记·算法·matlab·矩阵
量子炒饭大师1 小时前
收集飞花令碎片——C语言关键字typedef
c语言·c++·算法
澡点睡觉1 小时前
【数据结构与算法Trip第4站】摩尔投票法
算法
二进制_博客1 小时前
给CentOS的虚拟机扩容
linux·运维·centos
千钰v1 小时前
Tcpdump: The Basics Tcpdump 基础
linux·运维·网络·tcpdump·tryhackme
kk5792 小时前
【Ubuntu】sudo apt update出现E :仓库***没有Release文件
linux·运维·ubuntu
cellurw2 小时前
Linux下C语言实现HTTP+SQLite3电子元器件查询系统
linux·c语言·http