Linux之system函数--在程序中执行命令
来源:互联网 发布:微霸科技软件 编辑:程序博客网 时间:2024/05/29 17:13
NAME
system - execute a shell command
SYNOPSIS
#include <stdlib.h>
int system(const char *command);
DESCRIPTION
The system() library function uses fork(2) to create a child process that executes the
shell command specified in command using execl(3) as follows:
system() returns after the command has been completed.(注意,系统在命令执行完成的之后返回)
During execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT will be
ignored, in the process that calls system() (these signals will be handled according to
their defaults inside the child process that executes command).
If command is NULL, then system() returns a status indicating whether a shell is avail‐
able on the system
RETURN VALUE
The return value of system() is one of the following:
* If command is NULL, then a nonzero value if a shell is available, or 0 if no shell is
available.
* If a child process could not be created, or its status could not be retrieved, the
return value is -1.
* If a shell could not be executed in the child process, then the return value is as
though the child shell terminated by calling _exit(2) with the status 127.
* If all system calls succeed, then the return value is the termination status of the
child shell used to execute command. (The termination status of a shell is the termi‐
nation status of the last command it executes.)
In the last two cases, the return value is a "wait status" that can be examined using the
macros described in waitpid(2). (i.e., WIFEXITED() WEXITSTATUS() and so on).
system() does not affect the wait status of any other children.
system - execute a shell command
SYNOPSIS
#include <stdlib.h>
int system(const char *command);
DESCRIPTION
The system() library function uses fork(2) to create a child process that executes the
shell command specified in command using execl(3) as follows:
execl("/bin/sh", "sh", "-c", command, (char *) 0);
(其实就是使用fork创建一个sh进程,然后将命令传递给sh进程执行命令,注意这里要加一个“-c”选项,不然不能执行可执行命令而只能执行脚本命令。其实我自己也这样用过,但是不是使用sh来执行命令,而是直接把可执行程序用execl函数加载执行,这样也可以实现类似的功能,但是不能执行脚本文件/文件,因为脚本命令不是可执行文件,脚本文件是使用sh解析执行的。)
system() returns after the command has been completed.(注意,系统在命令执行完成的之后返回)
During execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT will be
ignored, in the process that calls system() (these signals will be handled according to
their defaults inside the child process that executes command).
If command is NULL, then system() returns a status indicating whether a shell is avail‐
able on the system
RETURN VALUE
The return value of system() is one of the following:
* If command is NULL, then a nonzero value if a shell is available, or 0 if no shell is
available.
* If a child process could not be created, or its status could not be retrieved, the
return value is -1.
* If a shell could not be executed in the child process, then the return value is as
though the child shell terminated by calling _exit(2) with the status 127.
* If all system calls succeed, then the return value is the termination status of the
child shell used to execute command. (The termination status of a shell is the termi‐
nation status of the last command it executes.)
In the last two cases, the return value is a "wait status" that can be examined using the
macros described in waitpid(2). (i.e., WIFEXITED() WEXITSTATUS() and so on).
system() does not affect the wait status of any other children.
阅读全文
1 0
- Linux之system函数--在程序中执行命令
- linux的system () 函数执行命令
- 在Linux中定时执行一个程序的方法之at命令
- 怎么在Android程序中执行Linux shell 命令
- 在linux应用程序使用system函数执行简单的shell交互命令的方法
- system函数在当前进程下执行一个新命令
- C语言中system()执行cmd命令打开关闭程序
- linux c system函数执行命令的返回值
- Linux system函数的执行命令并获取状态
- system函数 执行DOS 命令
- 在java程序中执行dos命令
- 在c++程序中执行DOS命令
- 在awk中执行system命令------太有用了
- php中exec函数执行linux命令
- 在 Android 中执行 Linux 终端命令
- 在android系统命令行中执行arm linux程序,出现/system/bin/sh: .xxx No such file or directory问题
- 在Linux中,设置前、后台命令和程序的执行
- Android之应用中执行Linux命令
- springmvc中@RequestParam和@PathVariable的区别和使用
- android 查看图片、保存图片
- php的memcache和memcached扩展区别
- Listener监听器之初使用
- 虚拟机 内存模型
- Linux之system函数--在程序中执行命令
- 2017.5.26信息课c++
- kill某个应用程序进程的方法
- opencv 模板匹配 matchTemplate
- mysql解压版安装教程
- C# Excel单元格属性
- POS 银行卡应用主要功能
- ISR 中断服务例程
- PHP中使用memcache(或者redis)存储session