system执行shell命令
system - execute a shell command
#include <stdlib.h>
int system (const char *command);
描述
system() executes a command specified in command by calling /bin/sh -c command, and returns after the command has been completed. During excution of the comman, SIGCHLD will be bocked, and SIGINT and SIGQUIT will be ignored.
返回值
错误返回-1,成功返回命令的退出状态。退出状态格式由wait指定,因此,命令的退出码是WEXITSTATUS(status). In case /bin/sh could not be executed, the exit status will be that of a command that dose exit(127).
If the value of command is NULL, system() returns nonzero if the shell is available, and zero if not.
system() does not affect the wait status of any other children.
注意
As mentioned, system() ignores SIGINT and SIGQUIT. This may make programs that call it from a loop uniterruptible, unless they take care themselves to check the exit status of the childl. E.g.
while(something) {
int ret = system("foo");
if(WIFSIGNALED(ret) && (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
break;
}
It is possible for the shell command to return 127, so that code is not a sure indication that the execve call fialed.
system执行shell命令的更多相关文章
- C语言system()函数:执行shell命令
头文件:#include <stdlib.h> 定义函数:int system(const char * string); 函数说明:system()会调用fork()产生子进程, 由子进 ...
- 在程序中执行shell命令
在linux系统下的操作中我们会经常用到shell命令来进行,一开始学习进程的时候对于shell命令也进行了思考,认为shell命令就是一个进程的外壳,经过了后来的学习对于这一点也有了更多的认识. 用 ...
- python(6)-执行shell命令
可以执行shell命令的相关模块和函数有: os.system os.spawn* os.popen* --废弃 popen2.* --废弃 commands.* ...
- Android执行shell命令
一.方法 /** * 执行一个shell命令,并返回字符串值 * * @param cmd * 命令名称&参数组成的数组(例如:{"/system/bin/cat", &q ...
- loadrunner调用plink,远程linux执行shell命令
loadrunner调用plink,远程linux执行shell命令 脚本: Action() { char* cmd; cmd = lr_eval_string("C:\\\&qu ...
- python 执行shell命令
1.os模块中的os.system()这个函数来执行shell命令 1 2 3 >>> os.system('ls') anaconda-ks.cfg install.log i ...
- python中执行shell命令的几个方法小结
原文 http://www.jb51.net/article/55327.htm 最近有个需求就是页面上执行shell命令,第一想到的就是os.system, os.system('cat /proc ...
- python中执行shell命令行read结果
+++++++++++++++++++++++++++++ python执行shell命令1 os.system 可以返回运行shell命令状态,同时会在终端输出运行结果 例如 ipython中运行如 ...
- mysq在命令行模式下执行shell命令
mysql可以在命令行模式下执行shell命令 mysql> help For information about MySQL products and services, visit: htt ...
随机推荐
- Editplus从下载到使用
☆ 准备工作 1,保证浏览器正常上网 2,能下载软件或已经下载到Editplus这个工具. ☆ 下载editplus 在浏览器输入http://www.editplus.com,然后回车.进入edit ...
- MySQL助理配置
基本配置 你需要经常察看以下3个配置项.不然,可能很快就会出问题. innodb_buffer_pool_size:这是你安装完InnoDB后第一个应该设置的选项.缓冲池是数据和索引缓存的地方:这个值 ...
- CSS3 3D Transform
CSS3 3D Transform 原文:http://www.w3cplus.com/css3/css3-3d-transform.html 三维变换使用基于二维变换的相同属性,如果您熟悉二维变换, ...
- cURL 学习笔记与总结(2)网页爬虫、天气预报
例1.一个简单的 curl 获取百度 html 的爬虫程序(crawler): spider.php <?php /* 获取百度html的简单网页爬虫 */ $curl = curl_init( ...
- 【翻译】Kinect v2程序设计(C++) Body 篇
Kinect SDK v2预览版的主要功能的使用介绍,基本上完成了.这次,是关于取得Body(人体姿势)方法的说明. 上一节,是使用Kinect SDK v2预览版从Kinect v2预览版取得B ...
- php数据缓存
用php进行微信开发时,碰到access_token长久保存的问题,以前都是用框架里的Cache直接set.get一下就完了.现在没框架可用了,只好自己动手写一个cache暂时用. 这个Cache类用 ...
- 函数式编程Map()&Reduce()
.forEach():每个元素都调用指定函数,可传三个参数:数组元素丶元素索引丶数组本身丶 , , , , , , , ]; a.forEach(function(v,i,a){a[i]=v+;}); ...
- git-svn
sudo apt-get install git-svn svn作为一个优秀源码版本的管理工具,可以适合绝大多数项目.但是因为它的采用中心化管理,不可避免的存在本地代码的备份和版本管理问题.也就是说对 ...
- mysql import data slow solution---overview information
1 SELECT SUM(DATA_LENGTH)+SUM(INDEX_LENGTH) FROM information_schema.tables WHERE TABLE_SCHEMA='dat ...
- windbg 命令 gchandles
使用windbg导出dump文件 .dump /ma D:\testdump.dmp gchandles命令列出句柄,同时列出句柄引用的对象,演示代码如下: using System; using S ...