4

Is there a way to check if a named program is currently running on an RPi? I am currently running my RPi headless with a VNC server over LAN to initiate the program and check it from time to time when I'm at home.

Now, I have SSH access to my device from anywhere and I wish to see if my script is running. Is there a way to do it?

Also is it possible to see the print values of that script running in the terminal?

The program runs on Raspbian OS on RPi 3.

Thanks!

1
  • 1
    FYI you should check the latest series on the blog (re: SSH) I am currently working on the SSH security section. Commented Aug 26, 2016 at 1:45

1 Answer 1

5

@SteveRobillard answered my question in the comments. I will re-iterate it here for everyone to see clearly!

1. Viewing running programs:

In the terminal type: ps aux | grep programname

ps = display currently running processes

a = show processes for all users

u = display the process' user/owner

x = show processes not attached to a terminal

grep = search for a name of the process (i.e. programname)

2. Viewing the currently open terminal session over SSH.

Use tmux or screen. I used tmux and followed instructions provided in the blog run by @jacob001 and @SteveRobillard: https://raspberrypise.tumblr.com/post/141348857424/tmux-101-installing-from-source.

Once tmux was installed, as per installation guide, I tested it by running my program through it on my RPi. Then I connected to the RPi remotely via SSH using my laptop (I used weaved.com service in this case). Once connected, I typed tmux in the terminal to run it and a new session opened. Subsequently, I typed CTRL-B then ( to switch to the previous session (the one I initialized earlier on my RPi). And voilà, this way I could access live program's output (printed sensor values) remotely!

Resources:

2
  • Would just pidof programname (found here) work for you as well?
    – uhoh
    Commented Mar 13, 2018 at 9:52
  • htop is very useful for any kind of process inspection
    – Neil
    Commented Dec 23, 2020 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.