How do I keep a program running after disconnecting from ssh?

182 views
Skip to first unread message

Denis Cosmin

unread,
Dec 27, 2016, 12:32:46 PM12/27/16
to BeagleBoard

Hello,

I use the BBB to turn on my christmas light using a simple relay circuit. I made a simple server in python that listens to post requests, so far it works, I also use Microsoft Cognitive Services to send post requests based on speech commands.
When I start up the python server: nohup python3 server.py & everything works fine while I am connected to the BBB over ssh but when I leave the server stops working.

Could you please give me some advice on how to keep python3 server running after I disconnect from ssh?

Denis Cosmin

unread,
Dec 27, 2016, 12:56:29 PM12/27/16
to BeagleBoard
I retried with nohup and it works now. I think I had problems in the sender code.

William Hermans

unread,
Dec 27, 2016, 9:05:28 PM12/27/16
to beagl...@googlegroups.com
Generally, all you need is '&' to send the process to the background. So if I had a Nodejs script called 'app.js' . . .

$ node app.js &

This would start app.js through node, then send the  process into the background. Giving me a PID which I could use later to kill the process.

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/167a3385-0126-4c45-a7f0-2cdd1796759b%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

woody stanford

unread,
Jan 28, 2017, 6:56:20 PM1/28/17
to BeagleBoard
There is kind of an involved way in C that is how it is done (similar to how Apache runs as a long-running daemon).

What you do is you fork() with the parameters set up such that it invokes a daughter shell process that survives after the parent process is terminated. The reason why the daughter process is shell, is so you can just call your python interpreter inside it. Even though it uses two languages, it is how its done for a stable service-type daemon.

I'll check back if there is any interest in seeing my C code for how to do this (I wrote something a little while ago that required this approach, so I have the source on hand and its all ANSI posix-compliant C with no external libraries).

Chris Green

unread,
Jan 29, 2017, 5:03:43 AM1/29/17
to beagl...@googlegroups.com
'woody stanford' via BeagleBoard <beagl...@googlegroups.com> wrote:
> >
> > I use the BBB to turn on my christmas light using a simple relay circuit.
> > I made a simple server in python that listens to post requests, so far it
> > works, I also use Microsoft Cognitive Services to send post requests based
> > on speech commands.
> > When I start up the python server: nohup python3 server.py & everything
> > works fine while I am connected to the BBB over ssh but when I leave the
> > server stops working.
> >
> > Could you please give me some advice on how to keep python3 server running
> > after I disconnect from ssh?
> >
Look at the 'nohup' command. Basically you do:-

nohup <my script> &

The & after the command puts it in the background, the nohup tells the
system not to send it a hangup signal when you disconnect ssh.

--
Chris Green
·

Reply all
Reply to author
Forward
0 new messages