Is it possible in Ubuntu to check if the following shell-executable is running? The name of the executable is ibgateway. When I run htop, the command that I see is the following, which means it is currently running.

 /bin/sh -c nohup "/home/user1/Jts/ibgateway/978/ibgateway" "-J-DCHANNEL=latest" "-J-DchannelChanged=false" "-J-DjtsConfigDir=/home/user1/Jts" "-J-Drestart=jdapbbikegkmhgpnhhk

I have tried pgrep ibgateway but it does not return anything although ibgateway is running. I am looking for a way to check from terminal that the above process is running or not.


user1@SFO:~$ cat /proc/11965/comm

user1@SFO:~$ cat /proc/11965/cmdline
/bin/sh-cnohup "/home/user1/Jts/ibgateway/978/ibgateway" "-J-DCHANNEL=latest" "-J-DchannelChanged=false" "-J-DjtsConfigDir=/home/user1/Jts" "-J-Drestart=jdapbbikegkmhgpnhhkpeglncdomifcjhpdimcbe"  > /dev/null 2>&1
  • 1
    Are you sure that is the code? That is not how -c works. When I run /bin/sh -c nohup touch nohup I get an error message from nohup (missing operands). Commented Aug 7, 2020 at 23:56
  • Yes. I copied the command from htop. Commented Aug 8, 2020 at 0:11
  • 1
    You are aware that what you type in a shell command line is not what you get in the process list (except for trivial cases without any shell features like quoting)? Run the command and see what happens. Commented Aug 8, 2020 at 0:17
  • 1
    Find out the PID of the process and add the output of cat /proc/$PID/comm and cat /proc/$PID/cmdline to your question. Commented Aug 8, 2020 at 0:33
  • Please see the updated question for the outputs for cat /proc/$PID/comm and cat /proc/$PID/cmdline Commented Aug 8, 2020 at 3:34

1 Answer 1


Your command should be:

/bin/sh -c 'nohup "/home/user1/Jts/ibgateway/978/ibgateway" '\
'"-J-DCHANNEL=latest" "-J-DchannelChanged=false" '\
'"-J-DjtsConfigDir=/home/user1/Jts" '\

All the " are unnecessary as there are no special characters which they could protect. And at the end one is even missing.

possible solutions


The probably best way to handle this is to use SystemD. Create a unit file, start the service with systemctl start ibgateway.service and query its state with systemctl status ibgateway.service. No need for sh, no need for `nohup.

You do not even have to create a unit file, you can just use systemd-run (as non-root):

$ systemd-run --user ./testscript.sh
Running as unit: run-r1422e75c673a4439aaacefd0df118a51.service

$ systemctl --user status run-r1422e75c673a4439aaacefd0df118a51.service
● run-r1422e75c673a4439aaacefd0df118a51.service - /home/hl/tmp/./testscript.sh
     Loaded: loaded (/run/user/1000/systemd/transient/run-r1422e75c673a4439aaacefd0df118a51.service; transient)
  Transient: yes
     Active: active (running) since Sat 2020-08-08 02:36:57 CEST; 26s ago
   Main PID: 7740 (testscript.sh)
     CGroup: /user.slice/user-1000.slice/[email protected]/run-r1422e75c673a4439aaacefd0df118a51.service
             ├─7740 /bin/bash /home/hl/tmp/./testscript.sh
             └─7742 sleep 100

check run status

The best approach seems to be:

$ systemctl show dracut-shutdown.service | grep -e ActiveState -e SubState       

$ systemctl show display-manager.service | grep -e ActiveState -e SubState

So you could grep for SubState=running (and ActiveState=active for a clean solution).

  • Sorry that my question was not clear enough. Please see the updated version Commented Aug 8, 2020 at 0:16
  • 1
    @AFP The command line in my answer does result in the process list entry you put in your question. Commented Aug 8, 2020 at 0:19
  • How do you query the operating system whether it is running or not? I would like to use this in a Python script to return for example a true or false. Commented Aug 8, 2020 at 3:36
  • 1
    @AFP I added some information to the answer. Commented Aug 8, 2020 at 4:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .