当前位置: 技术问答>linux和unix
system执行命令行参数问题
来源: 互联网 发布时间:2016-12-20
本文导语: 1.c #include #include #include #include #include #include #include #include void pr_exit(int status) //检查退出状态 { if (WIFEXITED(status)) { printf("normal termination ! exit status = %dn", WEXITSTATUS(status)); } else if (WIFSIGNALED(s...
1.c
#include
#include
#include
#include
#include
#include
#include
#include
void pr_exit(int status) //检查退出状态
{
if (WIFEXITED(status))
{
printf("normal termination ! exit status = %dn",
WEXITSTATUS(status));
}
else if (WIFSIGNALED(status))
{
printf("abnormal termination ! exit status = %d %sn",
WTERMSIG(status),
#ifdef WCOREDUMP
WCOREDUMP(status) ? "(core file generated)":" ");
#else
" ");
#endif
}
else if (WIFSTOPPED(status))
{
printf("child stoped, signal number = %dn",
WSTOPSIG(status));
}
}
int main(int argc, char *argv[])
{
int status;
status = system(argv[1]);
pr_exit(status);
return 0;
}
2.c
#include
int main(int argc, int *argv[])
{
printf("uid = %d euid = %dn",
getuid(), geteuid());
return 0;
}
结果:
[root@localhost work]# gcc 2.c -o 2
[root@localhost work]# ./2
uid = 0 euid = 0
[root@localhost work]# gcc 1.c -o 1
[root@localhost work]# ./1
abnormal termination ! exit status = 1
[root@localhost work]# ./1 2
sh: 2: command not found
normal termination ! exit status = 127
[root@localhost work]#
为什么没有正确运行,输出uid = 0 euid = 0?
#include
#include
#include
#include
#include
#include
#include
#include
void pr_exit(int status) //检查退出状态
{
if (WIFEXITED(status))
{
printf("normal termination ! exit status = %dn",
WEXITSTATUS(status));
}
else if (WIFSIGNALED(status))
{
printf("abnormal termination ! exit status = %d %sn",
WTERMSIG(status),
#ifdef WCOREDUMP
WCOREDUMP(status) ? "(core file generated)":" ");
#else
" ");
#endif
}
else if (WIFSTOPPED(status))
{
printf("child stoped, signal number = %dn",
WSTOPSIG(status));
}
}
int main(int argc, char *argv[])
{
int status;
status = system(argv[1]);
pr_exit(status);
return 0;
}
2.c
#include
int main(int argc, int *argv[])
{
printf("uid = %d euid = %dn",
getuid(), geteuid());
return 0;
}
结果:
[root@localhost work]# gcc 2.c -o 2
[root@localhost work]# ./2
uid = 0 euid = 0
[root@localhost work]# gcc 1.c -o 1
[root@localhost work]# ./1
abnormal termination ! exit status = 1
[root@localhost work]# ./1 2
sh: 2: command not found
normal termination ! exit status = 127
[root@localhost work]#
为什么没有正确运行,输出uid = 0 euid = 0?
|
lz最近帖子很多哈
会不会是你的PATH环境变量没有包含当前路径
试试./1 ./2
会不会是你的PATH环境变量没有包含当前路径
试试./1 ./2