Linux/Unix command to determine if process is running?

后端 未结 14 993
忘掉有多难
忘掉有多难 2020-11-28 01:54

I need a platform independent (Linux/Unix|OSX) shell/bash command that will determine if a specific process is running. e.g. mysqld, httpd... What

14条回答
  •  没有蜡笔的小新
    2020-11-28 02:32

    On most Linux distributions, you can use pidof(8).

    It will print the process ids of all running instances of specified processes, or nothing if there are no instances running.

    For instance, on my system (I have four instances of bashand one instance of remmina running):

    $ pidof bash remmina
    6148 6147 6144 5603 21598
    

    On other Unices, pgrep or a combination of ps and grep will achieve the same thing, as others have rightfully pointed out.

提交回复
热议问题