Questions tagged [background-process]

A 'background' process is a computer process that runs "behind the scenes" (i.e. in the background) and without user intervention. Typical tasks for using such processes include logging, system monitoring, scheduling, and user notification. Use this tag for any questions about background processes.

3
votes
2answers
6k views

Getting a pid for an ssh process that backgrounded itself

So I wanted to call two background ssh processes: ssh -D localhost:8087 -fN aws-gateway-vpc1 ssh -D localhost:8088 -fN aws-gateway-vpc2 These gateways don't have the benefit of letting me set an ...
0
votes
1answer
35 views

Background process killed after terminal closes

I have a pubsub python script. When I run the receiver script and send to the background using nohup and &, and close the ssh session, the process is killed. Is there any way to run receiver all ...
2
votes
2answers
25 views

toggle a program using bash script

I am trying to make a script that will toggle redshift (a night mode application). So, I've done this, #!/bin/bash pgrep redshift > /dev/null && \ killall redshift || \ ...
0
votes
0answers
48 views

Run script in background using `&` or `()&`?

If I want to run a script in background, for example a.sh, should I run ./a.sh & or should I put it in a subshell then background it? (./a.sh) & I test both and don't see difference, both ...
2
votes
1answer
43 views

How can I know if a process is running background or foreground in “ps” or “ps -ef” command output?

How can I know if a process is running background or foreground in commands ps or ps -ef? I first thought that when I type in ps -ef, there is a section named TTY. when I look into the list of TTY, ...
18
votes
8answers
19k views

How can I run `watch` as a background job?

When I run: watch 'cmd >> output.txt' & the job gets suspended by the system: 3569 Stopped (tty output) Is there a workaround?
3
votes
1answer
45 views

running ssh command with another command at the same time in a bash script

I have the following script #!/bin/bash for (( c=0; c<=9; c++ )) do ssh -t 192.168.30.11 "tshark -i eth1 -f 'src host 192.168.31.10 and tcp' -w shared_folder/results/bbb_var_4_exp_pcaps/...
0
votes
1answer
24 views

How to start my application after starting of “daemon” process in single script

I have a script, that starts my server. I want to start openvpn client before it. Here my current working solution: #!/bin/sh openvpn --client --config $OVPN_CONFIG & sleep 10 npm start I ...
2
votes
3answers
2k views

Wait multiple process, print exit code if any process get exit

What I am trying to achieve here is, via script I'm running 3 different custom application in wait simultaneously, if any application get exit, give alert via notify or print exit code. System in use:...
7
votes
2answers
23k views

Run commands in parallel and wait for one group of commands to finish before starting the next

I have script including multiple commands. How can I group commands to run together ( I want to make several groups of commands. Within each group, the commands should run in parallel (at the same ...
13
votes
4answers
3k views

What happens if I start too many background jobs?

I need to do some work on 700 network devices using an expect script. I can get it done sequentially, but so far the runtime is around 24 hours. This is mostly due to the time it takes to establish a ...
0
votes
1answer
78 views

Make process not exit, when exiting from SSH terminal

I just run bitcoind in centOS server. I run the following command nohup ./bitcoind > out & disown Then I exit the SSH terminal, and the process is automatically closed. Is there any way to ...
3
votes
4answers
14k views

How to return a background task to be in the foreground?

I would like to know how to stop a running process after appending it with &. For example, I would like to install software foo. Now, assume, foo has many dependancies, it takes an hour to ...
0
votes
3answers
2k views

top, top&, top & commands in linux

i don't understand the difference between "top, top&, top &" commands in linux.
4
votes
2answers
143 views

Inner for loop when run in background in bash spawns new bash process

I am executing below script LOGDIR=~/curl_result_$(date |tr ' :' '_') mkdir $LOGDIR for THREADNO in $(seq 20) do for REQNO in $(seq 20) do time curl --verbose -sS http://dummy.restapiexample.com/...
0
votes
2answers
916 views

How to re-write nohup.out?

I use nohup for running a command on a remote server in background, and use nohup.out file to check the progress. Can I set the nohup to re-write nohup.out as it only contains one line (the last ...
0
votes
0answers
50 views

Starting another program that shares output terminal with current program?

I have a matlab script that I run from the terminal, that script creates an instance of another program using: system('cd <path> && mpiexec -n 1 ./<program2> &') Problem is I ...
3
votes
3answers
3k views

How to wait for all spawned and backgrounded processes to finish in bash script

I've looked and looked and can't find a working solution to a bash script I'm trying to create to shut a process down and wait for it and spawned processes to finish. I'm still learning a lot of Linux....
1
vote
1answer
25 views

Killing two-part process with && by PID

I have a bash script where I am sleeping and then executing a command in a background process. For example sleep 30s && ./script.sh & If I grep ps for "sleep 30s" and kill the process ...
1
vote
1answer
70 views

Is there any difference to run a process in the background with an & vs when it has --daemonize option?

Some program has --daemonize option to run itself in background, e.g. php-fpm. I was wondering is there any difference between using --daemonize or just use the old & way to run the process in ...
1
vote
2answers
1k views

Unable to kill process, even with root. How to diagnose?

There are a lot of bash processes running on my Ubuntu Linux (12.04). Even when I close the terminal they are still shown in the System Monitor. I tried killing them as below, but they remain as it ...
1
vote
1answer
948 views

Job Control: How to save output of background job in a variable

Using Bash in OSX. My script has these 2 lines: nfiles=$(rsync -auvh --stats --delete --progress --log-file="$SourceRoot/""CopyLog1.txt" "$SourceTx" "$Dest1Tx" | tee /dev/stderr | awk '/files ...
1
vote
0answers
50 views

How to know end of background process

I have a script running in background ./test.sh & How can I know the completion of test.sh. I have to check the process id from an another console. Is there any another way
0
votes
1answer
38 views

Are processes within screen treated differently from foreground processes?

Assume I have a long running process, long_running_proc with a single TCP connection to host host.example.com. Is that process treated differently, by the OS or the shell, when it's run as a ...
1
vote
3answers
1k views

How to launch «gdbserver» in background?

I am communicating with a device via a serial port, and for I am launched «gdbserver» (like gdbserver :2345 myapp) it completely blocks the terminal. Neither an ampersand & symbol, nor ^z ...
1
vote
2answers
151 views

Automatic Background Processes

I'm running my Raspberry Pi off an SSH server, and want to be able to access it out of home. Sure, all I need is an IP. But with my terrible internet, it's constantly dropping out. My IP is constantly ...
4
votes
1answer
969 views

Launch background process from sh and close the terminal

How can this be achieved in sh (not bash!)? nohup sh -c 'helper-bcpy.sh "$0" "$1" "$2" "$3"' "$num" "$full_path" "$log" "$log_finished" >/dev/null & I would have expected it to send the ...
1
vote
1answer
246 views

launch reverse tunnel with autossh on bootup in Ubuntu

I would like to launch a ssh reverse tunnel on system launch. The following line let's me establish the tunnel fine - but I end up being logged into server which I don't want, especially not from an ...
6
votes
4answers
636 views

Run command in background with foreground terminal access

I am trying to create a function that can run an arbitrary command, interact with the child process (specifics omitted), and then wait for it to exit. If successful, typing run <command> will ...
-1
votes
1answer
134 views

Why does the process ID change in the output of “ps -l”?

Whenever I run a command in the terminal on Linux, at runtime, its PID changes. The command I used after running one program two times at runtime, was ps -l. Why does the program change process ID?
0
votes
0answers
49 views

How to execute unix command after few background jobs?

My c-shell code has to complete few concurrent background jobs before execution of some unix commands. However, somehow in code my background jobs never returns handle to unix commands. i.e. $cmd1 | ...
1
vote
0answers
117 views

Log python http server output to file

I want to start a python webserver in the background and log all of its output to file. Instead the the servers output appears in the terminal. Even tho i guess this is pretty basic ... I've got no ...
0
votes
0answers
45 views

How to get PIDs connected to another PID's standard input/output/error?

After something like first_command | … | last_command & $! is set to the PID of last_command. How can I find the other PIDs in this pipeline? Especially, is there a convenient way to find the PID ...
2
votes
1answer
1k views

SSH fork kills connection

I am using a Linux script which has the task of forwarding control of the system to remote support. In this script one of the commands is a ssh port forward command that will forward the port of the ...
1
vote
1answer
57 views

Can't run a background process and other command from bash in one line: unxepected token `;' [duplicate]

I have a program that receives an argument and prints it every second: ~# ./myapp 234 234 234 234 234 ... I want to be able to run it in the background and right after a shell but it must be in ...
297
votes
11answers
372k views

How can I run a command which will survive terminal close?

Sometimes I want to start a process and forget about it. If I start it from the command line, like this: redshift I can't close the terminal, or it will kill the process. Can I run a command in such ...
0
votes
0answers
32 views

Background processes in bash preserving order

From a GUI terminal emulator running bash, I would like to open a tabbed instance, get its X window ID, and use it to embed four st terminal instances inside tabbed, with titles from 1 to 4, in ...
18
votes
8answers
77k views

Calling multiple bash scripts and running them in parallel, not in sequence

Suppose that I have three (or more) bash scripts: script1.sh, script2.sh, and script3.sh. I would like to call all three of these scripts and run them in parallel. One way to do this is to just ...
1
vote
1answer
36 views

How to get variables expanded in output of jobs command

As you can see in the following output the variable $i in the output of ps aux is expanded to sleep 1, sleep 2, etc. Is there a way to make zsh do the same? In the jobs output all the commands get the ...
1
vote
1answer
50 views

Signal trap from background job without pressing enter

In Bash 5 I ran into a situation where I want to do the following: trap 'echo trapped!' USR1 while true; do kill -SIGUSR1 $$; sleep 1; done & But I have to press enter on keyboard every time the ...
7
votes
2answers
2k views

Is it possible to stop output from a command after bg?

Suppose this situation wget http://file wget starts to download file. I put it in the background. ^Z bg The command goes into the background. But its output is still on the console also -- if ...
0
votes
1answer
62 views

process running in background but still I cannot use the command line

I suspend a running process by ctrl+Z and the bg to place process in the background but the process still running in the foreground so I cannot use the command line. How can I put the process ...
185
votes
8answers
501k views

How to terminate a background process?

I have started a wget on remote machine in background using &. Suddenly it stops downloading. I want to terminate its process, then re-run the command. How can I terminate it? I haven't closed ...
0
votes
0answers
18 views

Question on Netstat output “app --node-in” & other

While doing "netstat -p", I got result out of which, I am unable to understand below output:- unix 3 [ ] STREAM CONNECTED 3889891 23976/app --node-in unix 3 [ ] STREAM CONNECTED 33223 ...
0
votes
0answers
37 views

Error when run multiple commands in one line in bash [duplicate]

I have a program named "mem" and it takes one arg. If I run it by ./mem 1, all things went well. But when I tried to run "mem" multiple times with different args like this: ./mem 1 & ; ./mem 2 &...
0
votes
0answers
43 views

Why does my infinite shell script occasionally stop?

I wrote a python script that I want to keep running indefinitely. Most of the time it sleeps, but every once in a while it has to come to life to do some operations. I need to keep it running on an ...
3
votes
2answers
220 views

How to quit command prompt after a sleeping command executes?

I have a simple script: f=1 # initial value loop(){ ... if [[ $f -eq 1 ]] then echo $msg1 f=2 (sleep $interval; loop) & exit 1 elif [[ $f -eq 2 ]] ...
2
votes
1answer
436 views

Bash - Execute background process whilst reading output

I'm trying to start a process (target_executable) and have it run in the background. I know I could do that via ./target_executable & but in the bash script that's running the show, I want to read ...
0
votes
1answer
106 views

How to avoid zombie process while working with named pipe?

We normally do the writing job to a FIFO file in background using a control operator &. Something like below. if [ ! -p "/tmp/mysqld.init" ]; then mkfifo /tmp/mysqld.init fi echo "something"...
2
votes
0answers
36 views

How to trigger a command after named pipe closes?

How can I execute some command after the named pipe has been readout in other end. I was trying to use trap. But nothing happens. My script is something like below. #!/bin/sh cleanup() { echo "...