nohup stops the process as soon as I press enter - linux

I'm trying to run a script, say script.py that does not take any input from the terminal in the background using nohup by
nohup python3 script.py &
This command worked perfectly the last time I used it (and the script kept running for days!), but some error interrupted the process and it stopped. Eventually, nohup.out contained no error. (Is it supposed to?)
Now, I'm trying to run the script again, but am failing to do so. I use the same command, and then open the running processes using top but I get:
[2]- Stopped nohup python3 script.py
[3]+ Stopped nohup python3 script.py
I am failing to understand why is this happening now. Any help is appreciated!
P.S: The script runs perfectly without nohup.

Related

How to kill a bash process running in the backend with nohup

I have a script forever.py which I want to run all the time in the background (also after that I close the terminal connected to the VM).
I used nohup python3 forever.py & and it worked, but the problem is that after some days it crashes (I guess due to memory overflow) and I need to restart it manually again.
To solve this, I did as suggested here, created a bash.sh file containing:
#!/bin/bash
until python3 forever.py; do
echo "'forever.py' crashed with exit code $?. Restarting..." 2>stderr.txt
sleep 1
done
and in the terminal, ran the command:
nohup bash bash.sh &
Currently it's running well and I hope the it restart when the program crashes.
My question is: how do I stop the execution of this?
I tried pkill nohup but it doesn't work!
Suggesting to investigate more about pkill command here:
pkill -9 -x "forever.py"

Bash script how to run a command remotely and then exit the remote terminal

I'm trying to execute the command:
ssh nvidia#ubuntu-ip-address "/opt/ads2/arm-linux64/bin/ads2 svcd&"
This works so far except that it hangs in the remote terminal when "/opt/ads2/arm-linux64/bin/ads2 svcd&" is executed, unless i enter ctrl+c. So I'm looking for a command that, after executing the command, exits from the remote terminal and continue executing the local bash script.
thanks in advance
When you run a command in background on a terminal, regardless of weather it be local or remotely, if you attempt to logout most systems will warn you have running jobs. One further attempt to logout and your jobs get killed as you exit.
In order to avoid this you need to detach your running jobs from terminal.
if job is already running you can
disown -h <jobspec ar reported by jobs>
If you want to run something in background and then exit leaving it running you can use nohup
nohup command &
This is certainly ok on init systems ... not sure if it works exactly like this on systems that use systemd.

How to Check Python3 Process running on macOS background terminal?

I'm running one python script using : nohup - python3 name.py >/dev/null & - to run one script in the background of my terminal. However would like to know best command to see a list of just python3 process running. i tried ps -xal|grep python3 (what i use on Linux) but was not working.
Thanks a lot ! :/)

command runs fine as standalone but not with nohup

I have a python script I am trying to run using nohup.
This script runs perfectly with:
python3 script.py
But when run as:
nohup python3 script.py &
It gets stuck.
This script uses python multiprocessing
and gets stuck at
mp.Pool(mp.cpu_count())
Solved the problem.
One of the first things to check is, that if your python script is running.
If it is, the problem is because of buffering.
Run your command as:
nohup python3 -u script.py &

jobs find nothing after nohup a script

I made a python script running on background:
nohup python app.py &
then close the terminal, a few days later, I want to see this job, so I run
jobs
there list no jobs, but I'm sure the script app.py is still running.
jobs will only give you a list of process running under the session group of the bash shell. nohup processes run in their own session group. There are a number of simple commands you can run to check if your nohup'd process is still running, the simplest being lsof | grep nohup (this command may take a few seconds to run)

Resources