0

I have developed a line-following vision application for the raspberry pi, and I want it to run always, as the Pi is connected to a robot. I know how to edit the rc.local file so that the application will run on boot, but I also need to be able to SSH into the Pi in order to change some parameters as the program is running. So how do I SSH into a running instance of an application?

1

2 Answers 2

1

Another alternative to screen is tmux.

You could get it instantly using

apt-get install tmux

Works similar to Screen but has been more up-to-date compared to screen

General Idea with tmux

  1. open a session : tmux new-session -d -s mySession (here -d is for detached mode which lets you run the application in the backend)

  2. In the same session open a new window: tmux new-window -d -n 'windowName' -t mySession:1 'yourCommandsGoHere with the Quotes'(-n is to name this new window and -t is for you to refer to which instance of the session is running)

  3. Follow step 2 as for as many applications that you need to run

  4. since all the sessions and windows are detached you could login to the pi any time and do the following to know the following:

To check which sessions are still available

tmux ls

to attach a particular session

tmux attach -t mySession

Once inside you could check all the applications using the ctrl+b 0-9 (press ctrl+ b first and then the number)

In the end if need be you can kill sessions using:

tmux kill-session -t mySession

tmux has a very well descripted man page (use man tmux) and plenty of help online with great cheatsheets like this

7
  • Thank you! Now how would I automatically setup a session that starts a c++ application when booting? Mar 2, 2016 at 14:34
  • put the session you want to create in a bash script and execute the c++ code you want to run in the script itself. if you want to run it at startup try keeping it in /etc/rc.local or use crontab
    – Shan-Desai
    Mar 2, 2016 at 14:57
  • when using rc.local I can see that application is actually running however when I try to attach to the session or use tmux ls nothing shows up. Mar 2, 2016 at 15:03
  • have you tried using /usr/bin/g++ because I have been facing a similar problem on this Thread
    – Shan-Desai
    Mar 2, 2016 at 15:14
  • I worked using @reboot in crontab when both tmux commands was on same line separated with ";". Thank you! Mar 2, 2016 at 15:17
1

Run your program under GNU screen :

screen -S mysession -d -m myapp

Now you can SSH into your Pi and switch to your app

screen -DR mysession

Added bonus is that your program doesn't die with your SSH connection.

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.