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

相关推荐
CC.GG5 分钟前
【Linux】进程控制(二)----进程程序替换、编写自主Shell命令行解释器(简易版)
linux·服务器·数据库
数研小生15 分钟前
Full Analysis of Taobao Item Detail API taobao.item.get
java·服务器·前端
2401_8384725118 分钟前
C++图形编程(OpenGL)
开发语言·c++·算法
-dzk-22 分钟前
【代码随想录】LC 203.移除链表元素
c语言·数据结构·c++·算法·链表
H Journey35 分钟前
Linux 下添加用户相关
linux·运维·服务器·添加用户
进击的小头1 小时前
陷波器实现(针对性滤除特定频率噪声)
c语言·python·算法
知无不研1 小时前
冒泡排序算法
算法·冒泡排序·排序
毅炼1 小时前
hot100打卡——day17
java·数据结构·算法·leetcode·深度优先
Tisfy1 小时前
LeetCode 3010.将数组分成最小总代价的子数组 I:排序 OR 维护最小次小
算法·leetcode·题解·排序·最小次小值
零基础的修炼1 小时前
Linux网络---网络层
运维·服务器·网络