Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
1answer
8 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 ...
0
votes
0answers
30 views

Wait command in Bash script not acting as expected [closed]

I am making a script to play 4 different video feeds from 4 different camera DVRs via RTSP, and need them to be pretty much hands-free i.e. a dedicated mini pc running Debian that will, network ...
1
vote
1answer
53 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
884 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
40 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
35 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
147 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
894 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
209 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
367 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
83 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
43 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
34 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
36 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
30 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 ...
288
votes
11answers
360k 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
27 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 ...
17
votes
8answers
76k 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
33 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
46 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 ...
6
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
46 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 ...
179
votes
8answers
487k 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
24 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
193 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 ]] ...
1
vote
1answer
121 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
62 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 "...
1
vote
2answers
51 views

Everything should be run in background instead of waiting

I have written a script that takes commands from user and runs through a huge list of servers and writes to a single file. Once writing has completed it triggers an email. My requirement is: the ...
8
votes
3answers
1k views

Why can't I see the “wget” job when I execute it in the background?

I use wget command in the background like this wget -bq and it prints Continuing in background, pid 31754. But when I type the command jobs, I don't see my job(although the downloading is not ...
9
votes
3answers
651 views

“Variabilize” the ampersand (background a process)

I want to know if there's a way to put the ampersand in a variable and still use it to send a process to the background. This works: BCKGRND=yes if [ "$BCKGRND" = "yes" ]; then sleep 5 & ...
0
votes
0answers
55 views

How to run vlc stream in background on raspbian?

I'm having trouble launching a command line in background. The command I'm trying tu run in background is : raspivid -o - -t 0 -n | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/cam}' :...
44
votes
4answers
16k views

What's the difference between running a program as a daemon and forking it into background with '&'?

What are the practical differences from a sysadmin point of view when deploying services on a unix based system?
2
votes
6answers
4k views

Killing the previous instances of a script before running the same Unix script

I want to kill the background process belonging to a shell script that I am going to run again. That means before executing the shell script I want to delete the background process running for the ...
0
votes
0answers
34 views

Use 'ssh ps aux' to gurantee process alive, mistake sometime

Q1 : Recently, some operations scripts is deployed on machine-01, in order to monitor process alive in remote machines. This feature is done by periodly do following cmd: ssh $ip "ps aux | grep $...
3
votes
1answer
73 views

Does ` (sleep 123 &)` remove the process group from bash's job control?

Does the following way $ (sleep 123 &) $ jobs $ remove the process group of sleep 123 from bash's job control? What is the difference between the above way and disown then? Note that the sleep ...
3
votes
3answers
2k 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....
7
votes
3answers
933 views

How to analyze this command `{ 2>&3 “$@”& } 3>&2 2>/dev/null`?

A few weeks ago, I have seen a weird answer about the question "(How to) silently start task(s) in the background?". This solution seems incorrect (c.f. my answer) although the shell seems to start ...
0
votes
0answers
59 views

Time Machine analog for Linux

On my Apple Mac I use TimeMachine to save backups. This is effortless and quite reliable and provides access to time-stamped historical files going back years. It is also efficient (the backups ...
1
vote
2answers
136 views

Background process of subshell strange behaviour

I wonder why some similar bash commands behave the way they do. I have a bash script foo: #!/usr/bin/env bash while true do echo "reading" read data echo $data echo "stderr msg" >...
0
votes
1answer
38 views

If you put something in the background does this mean it may also ignore interrpts?

I know that you can kill the process by job ID or PID using PS or KIll. but if its in the background using '&' will sending an interrupt signal will it also kill that process or Job?
1
vote
1answer
57 views

Killing background processes started in nix-shell

I am developing a simple data science environment with Python tools and a database. When I enter the nix-shell, I spin up the database process. I would like to spin it down when exiting the ...
2
votes
2answers
190 views

Background execution in parallel

I have a program ./pgm taking some arguments (say -a file1 -b val), which requires 2 seconds to execute. I would like to use all the processors on my machine to run this program on all the input files ...
233
votes
5answers
276k views

How to get the pid of the last executed command in shell script?

I want to have a shell script like this: my-app & echo $my-app-pid But I do not know how the get the pid of the just executed command. I know I can just use the jobs -p my-app command to grep ...
2
votes
1answer
107 views

Do the Firefox children processes correspond to number of tabs?

I am running Firefox Quantum 63.0.3 (32-bit) on Ubuntu. In output of htop command (sorted by Command name) I see the following I see 6 children process below the original firefox process. What do ...