64位linux ps命令执行问题

奕诚 2015-08-05 04:16:30
如题,在64linux 终端 下 输入如下命令:
ps -ef | grep ora_ |grep XXX|wc -l
输出为0
但是在linux C程序下用 popen 执行,输出为1;
请问各位linux大神,为什么执行同样的命令,在终端下和程序下执行结果不一样呢?
PS:如果在终端下执行ps -ef | grep ora_ |grep XXX|wc -l 结果大于0的话 在程序里popen 执行输出的结果一样。
...全文
188 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
奕诚 2016-10-10
  • 打赏
  • 举报
回复
3楼正解。可惜不能结贴给分了,十分抱歉,感谢楼上各位的热心解答!
nswcfd 2015-08-07
  • 打赏
  • 举报
回复
是不是执行popen的程序本身,也匹配上XXX了?
  • 打赏
  • 举报
回复
oops, I meant "including the one created by popen" The popen() function opens a process by creating a pipe, forking, and invoking the shell.
  • 打赏
  • 举报
回复
that's because you pass -ef to ps, which will list all processes on the system, including the one created popen, it loos like sh -c ps -ef | grep ora_ |grep XXX|wc -l so the correct line count should be whatever you read from pipe minus 1
大熊猫侯佩 2015-08-05
  • 打赏
  • 举报
回复
你将返回0的命令串拆开,从头开始一段一段检查
羽飞 2015-08-05
  • 打赏
  • 举报
回复
把popen去掉wc -l看看结果是啥

23,217

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧