2

I'm running a python script in the background on an Ubuntu ssh server. nohup python x.py & After a certain amount of time, maybe half an hour, the python script stops running when I come back into the server and type ps. Not sure why. I don't want it to ever time out.

1 Answer 1

4

Processes in an SSH session belong to your shell's process; typically:
sshd [your-username] tty[your-tty].

When you kill your session, all child processes are also exited.

To get around this, use terminal multiplexing, or daemons.

The most common multiplexers are screen and tmux.

You would then start screen by using the screen -S my-session-name, and running your process normally.

You can then press ctrl+a, d to detach from the screen, and the process will still be running, but as a child of screen, not your ssh session

To reattach, type screen -x my-session-name (-r also works)

6
  • So why doesn't screen die for the same reason the python script does? Nov 21, 2013 at 18:30
  • Getting a memory error now, program doesnt run as far as it did before
    – John
    Nov 21, 2013 at 18:35
  • 1
    @MattiasÅslund screen creates another TTY in /tmp (a socket, really), that will have processes belonging to it, rather than using your current TTY (which will be in /dev/tty[id]), since that will go poof when sshd decides it's time to exit. you call screen; it's not invoked by your shell
    – Amelia
    Nov 21, 2013 at 18:37
  • @Anonymous are you sure you weren't running into swap space previously?
    – Amelia
    Nov 21, 2013 at 18:38
  • I think so. Before I loaded data and processed it for some time and I guess when I exited, the process stopped. Now the program throws a memory error when loading the data, doesn't even get to the processing.
    – John
    Nov 21, 2013 at 18:40

You must log in to answer this question.

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