- 论坛徽章:
- 0
|
在system函数中:
#include <sys/wait.h>
#include <errno.h>
#include <unistd.h>
int
system(const char *cmdstring) /* version without signal handling */
{
pid_t pid;
int status;
if (cmdstring == NULL)
return(1); /* always a command processor with UNIX */
if ((pid = fork()) < 0) {
status = -1; /* probably out of processes */
} else if (pid == 0) { /* child */
execl("/bin/sh", "sh", "-c", cmdstring, (char *)0);
_exit(127); /* execl error */
} else { /* parent */
while (waitpid(pid, &status, 0) < 0) {
if (errno != EINTR) {
status = -1; /* error other than EINTR from waitpid() */
break;
}
}
}
return(status);
}
execl("/bin/sh", "sh", "-c", cmdstring, (char *)0);的"sh"是什么意思? 拿来有什么用?
我做了下实验:
把execl("/bin/sh", "sh", "-c", cmdstring, (char *)0);换成execl("/bin/sh", "xx", "-c", cmdstring, (char *)0);
程序照样能正常运行,但是如果直接把"sh"删了,就不行~
根据这个实验我猜测/bin/sh所指向的文件/bin/bash是一个解释器文件,但是用vi查看其内容并没有#! pathname .....,而
是一个二进制文件,为什么,想不通~~~~ |
|