【问题标题】:What does ps h -fwC do?ps h -fwC 有什么作用?
【发布时间】:2013-08-10 11:08:15
【问题描述】:

如何理解这部分脚本?调用 ps h -fwC ifmFuseHandler 会给出以下输出:

DRBimg:/tmp # ps h -fwC ifmFuseHandler
insite1  29149     1  0 11:57 ?        Ssl    0:00 ifmFuseHandler -o allow_other /opt/insiteone/fuse-mount

我对 ifmFuseHandler 在什么条件下启动特别感兴趣?

这是完整的脚本(一些摘录形式):

 # START IFM
        if [ $MYTYPE = "ifmFuseHandler" -o $MYTYPE = "ALL" ]
        then
            # IF A PROXY
            if [ $PROXY -eq 0 -a $DOIFM -eq 1 ]
            then
                # Make sure the fuse module is loaded
                FUSE=`lsmod | grep fuse`
                ret=$?
                if [ $ret -ne 0 ]
                then
                        /sbin/modprobe fuse 2>/dev/null
                fi
                FOUND=1
                #PID=`df | awk '/ifmFuseHandler/ {print $1}'`
                #PID=`ps -ef | grep -v 'awk' | awk '/ifmFuseHandler/ { print$2 }'`
                PID=`ps h -fwC ifmFuseHandler | awk '/ifmFuseHandler/ { print$2 }'`
                if [ "x$PID" = x ]; then
                    msg "Starting ifmFuseHandler..." $MSG_ALL
                    su - $USER -c "cd $DIR_INDEX;ifmFuseHandler  $IFM_SINGLE_THREAD -o allow_other $IFM_MOUNT"
                else
                    msg "ifmFuseHandler already running! PID=$PID" $MSG_ALL
                fi
            fi
        fi

【问题讨论】:

  • 可执行文件的位置没有任何意义 - ps 告诉你 process status - 我发现 man ps 会回答你的所有问题。
  • 不,它没有。我知道 ps 做了什么,但不确定 ifmFuseHandler 是如何启动的,以及它的参数是什么。
  • 在这两者之间,我编辑了我的问题。

标签: linux shell process command


【解决方案1】:

它只是使用 ps 的 -C 选项。比较

ps h -fwC ifmFuseHandler

ps h -fw

在外壳中。

【讨论】:

  • 为什么不使用ps -ef | grep ifmFuseHandler?中间的“h”是什么意思?对不起,如果我听起来很愚蠢。
  • 说真的,请阅读手册页,它都在里面。在这种情况下,没有区别,因为只是提取了 pid,但两组选项返回了一些不同的信息。
【解决方案2】:
PID=`ps h -fwC ifmFuseHandler | awk '/ifmFuseHandler/ { print$2 }'`

给你 ifmFuseHandler 的 PID

if [ "x$PID" = x ]; then

测试是否返回了 PID;如果没有,则启动 ifmFuseHandler,否则会打印消息表明它已经在运行

我自己,我会跑

PID = `ps -el|grep -v grep|grep ifmFuseHandler|awk '{print $2}'`

【讨论】:

  • 你能告诉我不使用简单的原因吗:ps -ef | grep ifmFuseHandlerh 代表什么?
  • 查看我帖子的最后一行 - 简单得多(另外,你真的必须阅读 ps 的手册页,你所有的问题都在那里得到解答......)
  • @KevinDTimm 您可以使用ps h -C ifmFuseHandler --format "%p"... h 保存所有这些管道以进行无标题输出,-C arg 限制搜索,--format "%p" 仅打印 PID。 ..
  • @twalberg - 是的,但我是老派 unix(30 岁 +/-),所以我的手指有时会死记硬背 :) 但是,我今天确实学到了一些关于 ps 的东西,感谢您和 OP。
  • @KevinDTimm derp... 在这里我以为我只有 27 年的时间... ;-P
猜你喜欢
  • 2017-09-23
  • 2019-10-19
  • 1970-01-01
  • 2015-05-24
  • 1970-01-01
  • 2018-10-08
  • 1970-01-01
  • 2011-04-20
  • 2015-03-30
相关资源
最近更新 更多