I am executing a background process with the following command:
{ geth | node | whatever } &
When I check the jobs the status of this process is always Stopped.
If I add this command to a .sh file and I execute it the same way, it also happens.
Any idea why it is happening or any other solution to make background processes using just command lines?
Try running with nohup. You can analyse the nohup.out log if it still stops.
nohup script.sh
Related
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.
I need to execute this command on my terminal, that will operate on a server. I need to modify it such that if I lost the connection and the terminal closes, the operation running is not stopped, continuing the operation until its conclusion.
for file in 4458*/payoffTable* ; do cp "$file" /storage/scratch2/id0056/DMM_BASTIAN/M_7/N_15_P_05/Evoluzioni;done &
I know there is a command, called "nohup", that allow that, but if I prepend it to the previous command I get an error.
Also, in the case in which some of you is able to give a solution to this problem, I would like to know how to monitor the background processes running on a remote server. Thanks for the help.
After the execution of nohup the terminal returns the PID (Process ID) that is the process identifier.
By opening a terminal and running the command
ps -ef | grep PID
the console returns your process created above, if still running. If the process is not returned, it means that the execution is completed.
I want to run a command silently via ssh and exit the shell, but the program should continue running.
I tried screen and nohup, but apparently with those it executes 3 processes instead of 1:
user:/bin/bash ./[script]
root: sudo [commandInTheScript]
root: [commandInTheScript]
What am I doing wrong?
P.S.: The thing is that I want to run this command with the Workflow app (iOS), but the app waits until the command is finished, so it freezes 'forever'
To run your process back ground, at end of the command you have to use &.
In your case, you have to run without session since you are planning to exit from ssh after execute the command, so you need nohup
nohup <command> &
nohup < command > &
This makes your command runs on background and shows its PID
How did you use nohup?
Eg.
nohup ruby server.rb &
Ampersand (&) is necessary to let command run in the background.
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)
Well, I'm basically trying to make a bash script runs a node script forever. I made the following bash script:
#!/bin/bash
while true ; do
cd /myscope/
unlink nohup.out
node myscript.js
sleep 6
done & echo $! > pid
I'm expecting that when it runs, it starts up node with the given script, checks if node exits, sleeps for 6 seconds if so and reopen node. Also, I'm expecting it to run in background and writes it's pid (the bash pid) on a file called "pid".
Everything explained above works as expected, apparently, but I'm also expecting that when the pid of the bash script is killed, the node script would stop running, I don't know why that made sense in my mind, but when it comes to practice, it doesn't work. The bash script is killed indeed, but the node script keeps running and that is freaking me out.
I've tested it in the terminal, by not sending the bash script to the background and entering ctrl+c, both scripts gets killed.
I'm obviously miss understanding something on the way the background process works. For god sake, can anybody help me?
There are lots of tools that let you do what you're trying, just two off the top of my head:
https://github.com/nodejitsu/forever - A simple CLI tool for ensuring that a given script runs continuously (i.e. forever)
https://github.com/remy/nodemon - Monitor for any changes in your node.js application and automatically restart the server - perfect for development
Maybe the second it's not what you're looking for, but still worth a look.
If you can't or don't want to use those then the problem is that if you kill the parent process the child one is still there, so, you should kill that too:
pkill -TERM -P $PID
where $PID is the parent PID.