system()函数

来源:互联网 发布:网络集线器hub 编辑:程序博客网 时间:2024/06/06 00:10

int system(const char *command);

int system(Shell字符串)

头文件:

#include <stdlib.h>

返回值:

-1失败
127无法启动shell来运行
其他命令退出码

特点:

一次调用,一次返回。

本质:

直接用shell执行命令/程序

例子:

#include <stdio.h>#include <stdlib.h>#include <unistd.h>int main(int argc,char** argv){printf("PID:%d\n",getpid());system("sleep 3&");printf("PID:%d\n",getpid());}


       


      
0 0
原创粉丝点击