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

相关推荐
We་ct几秒前
LeetCode 138. 随机链表的复制:两种最优解法详解
前端·算法·leetcode·链表·typescript
dcmfxvr2 分钟前
【无标题】
java·linux·前端
dust_and_stars2 分钟前
Windows 11 RDP Wrapper 配置教程与常见问题解决方法
运维·windows
灰子学技术5 分钟前
istio从0到1:如何解决同一个应用不同功能的路由聚合问题
运维·服务器·网络·云原生·istio
步步为营DotNet10 分钟前
深入剖析.NET中Span:零拷贝内存操作的基石
服务器·php·.net
llz_11210 分钟前
蓝桥杯备赛-搜索(DFS/BFS)
c++·算法·蓝桥杯·深度优先·宽度优先
敲上瘾12 分钟前
磁盘到 inode:深入理解 Linux ext 文件系统底层原理
android·linux·运维·文件系统
Mr.小海13 分钟前
Docker Swarm 集群实战指南:从搭建到生产落地的完整攻略
运维·docker·容器
白云偷星子14 分钟前
RHCSA笔记2
linux·运维