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.
646 questions
0
votes
1
answer
30
views
Examining jobs submitted in other sessions
A semi-hypothetical question...i've logged into a machine remotely, set up a series of tasks along the lines of
sleep 36000 ; source myjob1 &
sleep 36000 ; source myjob2 &
(etc.) and then ...
7
votes
3
answers
874
views
Open pdf files in the background with fzf
I want to fzf through all the pdf files in a directory, open it and release the terminal.
I tried
PDF_READER=okular # or evince
find -type f -name "*.pdf" -print | fzf --print0 | xargs -0 $...
2
votes
0
answers
60
views
How to ensure processes/windows in background virtual terminals run?
I use two graphical virtual terminals (sessions) on a debian desktop with KDE (the ones you switch between using chvt or Ctr-Alt-F7, F8, etc.). I notice that processes in open windows in the inactive ...
4
votes
4
answers
551
views
How to wait for background commands that were executed within a subshell?
Given this code:
#!/bin/bash
set -euo pipefail
function someFn() {
local input_string="$1"
echo "$input_string start"
sleep 3
echo "$input_string end"
}
function ...
0
votes
1
answer
78
views
How to redirected output from disowned process to a file
A borgmatic backup command that runs for many hours:
long_running_cmd &> file.txt
I did Strg+Z then bg then disown to keep the command running I case my laptop goes to sleep or disconnects.
I ...
1
vote
1
answer
82
views
Process run with nohup gets killed on client_loop: send disconnect: Broken pipe
I have observed the following and want to understand why:
First, I run a Node server that listens on a port on a remote server using:
nohup my-app &
Next there are two cases:
I logout of the ...
1
vote
0
answers
190
views
How to wait the end of a non-child process?
I have here a not really fine app, partially out of my control. Sometimes it stops and I want to restart it, and some extra options.
So, if it exists, I want to start my script. Poor man solution ...
0
votes
2
answers
97
views
Why can't & and ; be used together (two processes started, first in the background)? [duplicate]
I tried this simple test
ping [SOME IP] &;ls
expecting the output of ping to overlap with the listing.
Instead, I got an error:
bash: syntax error near unexpected token `;'
It does not help ...
0
votes
0
answers
109
views
How Do SSH-Launched Long-Running Background Jobs Detach Without nohup or disown?
When running a long-running command in the background over SSH from a non-interactive shell script, I noticed the process continues running on the remote machine without using nohup, disown, or ...
2
votes
2
answers
133
views
Should launching background jobs cause a race condition?
I tested the following with both bash and dash, and it seems to reliably hang:
[ -p pipe ] || mkfifo pipe
i=0
while [ $i -lt 10 ]; do
<pipe cat &
: $(( i+=1 ))
done
# sleep 1
echo hello ...
0
votes
1
answer
126
views
Is it possible that systemctl process would not run without me being logged in to the server?
I am very new to linux and I need some help. I am trying to put blockchain node processes on the background so that they run without my being logged in.
I am using systemctl to run my process in the ...
2
votes
1
answer
359
views
Can one execute a function in background from a function that is already running in background?
Considering the following script:
if [[ -z "$DOWNLOAD_ONLY" || "$DOWNLOAD_ONLY" = *conditions* ]]; then
function get_condition {
curl -s "https://conditions.com" | ...
0
votes
1
answer
623
views
Systemd kills all background processes after ssh session ends despite all the typical solutions
I have tried almost every solution on Stack Exchange (except for nohup; it seems like that is not an ideal loophole), but Systemd still kills my background processes.
I also tried starting a Tmux ...
3
votes
0
answers
197
views
Understanding piping to a unix domain socket in the background
I have a Debian 12 (bookworm) host where I run three VMs using QEMU / KVM. To simplify VM management, each VM has a QEMU monitor socket. These sockets are /vm/1.sock, /vm/2.sock and /vm/3.sock. Among ...
0
votes
0
answers
121
views
How to continuously log process changes on a Linux system using built-in tools?
I have root access to a Linux system and need to log processes without installing any additional software, using only built-in tools like top. However, I want the process to run in the background ...
0
votes
2
answers
155
views
How to remove a background process whose pid was hidden
According to this answer to How to Hide PID and Exit Status When Running a Background Command in Terminal, using (some command &) one can stop the PID of the background process from appearing in a ...
2
votes
0
answers
76
views
Why does wait return 127 only if lastpipe is enabled?
I don't understand why wait returns 127 in this case. According to man bash, this happens if the subprocess does not exist anymore. This seems to not be the case.
This is the minimal example:
#!/usr/...
4
votes
0
answers
129
views
Does the shell's & operator perform redirects before or after starting asynchronous commands?
Consider the following script:
rm -f /tmp/bar
echo foo >/tmp/bar &
tail -f < /tmp/bar
When processing the echo line, does the shell first perform the redirect opening /tmp/bar for writing ...
0
votes
2
answers
195
views
Can I reuse a loop variable for a background task in a loop in bash?
I have an array, a=(...), and a function, b {}, which takes an argument.
I want to build a loop for i in ${a[@]} to traverse the values of a. In the loop, I use commands like (b $i) & to multitask....
1
vote
1
answer
1k
views
How to place a qemu vm in background (it means that it should run between the processes but nothing should be shown on the screen)
I would like to run the qemu vm that you see below runs between the processes,so I don't want to see any monitor,graphic,terminal window,nothing should be shown on the screen.
/usr/local/bin/qemu-...
1
vote
1
answer
104
views
How to detach a piped command from the terminal?
I want to allow the leading program(s) to operate in a standard manner and detach from the terminal once a graphical application launches. In this example fzf reads paths from a file, feeds the ...
0
votes
1
answer
148
views
Linux server accessing a background process started at bootup
before I explain my issue I should mention that I'm relatively new to Linux so please forgive my ignorance.
I'm using an old Dell E10S to act as a dedicated Minecraft server.
I managed to install ...
0
votes
1
answer
72
views
When does a hup signal affect the parent process? [duplicate]
If I run ./script.sh &, where script is the following:
#!/bin/bash
echo "hello"
sleep 30
echo "hello again"
sleep 30
touch /root/foo.txt
Then I use ps au, to identify the "...
0
votes
1
answer
218
views
Prevent defunct of child process when systemctl exits
I have 1 service registered with systemd
open_ssh.script
autossh -M 0 -L 8080:127.0.0.1:8080 -i .ssh/id_rsa USER@HOST -fN
auto_open_ssh.service
[Unit]
Description=SSH Tunnel Service
After=network....
0
votes
0
answers
52
views
How to run a process in the background using a bash script? [duplicate]
When I run the command in the terminal: sudo badvpn-tun2socks --tundev tun0 --netif-ipaddr 10.0.0.2 --netif-netmask 255.255.255.0 --socks-server-addr 127.0.0.1:8080 I get a terminal with packet data ...
14
votes
2
answers
2k
views
Run two scripts after each other in the background? && and & don't work?
I want to run two shell scripts after each other, in the background, preferably also using nohup.
I start with
% nohup a.sh &
This runs a in the background.
% nohup a.sh && nohup b.sh
...
1
vote
1
answer
654
views
How to pass the standard input of a shell script to a background command
In a shell script, I am trying to start a background command that has the same stdin as that of the shell script.
#!/bin/sh
# ...
the-program &
However, the-program above will not have access to ...
5
votes
3
answers
1k
views
Open PDF from a command line and go back to the command line
I would like to open a PDF with evince from the command line and after the Evince window pops up, I want to go back to the terminal command with $ already waiting for the next command.
Now if I run ...
1
vote
1
answer
135
views
Background process is not being terminated by SIGINT when executed via ssh
I was experimenting with ssh, nohup, bg etc. I started a tail process in remote using
$ ssh remotehost '{ nohup tail -f ut.log &> /dev/null < /dev/null &} && echo $!'
It ...
2
votes
3
answers
896
views
How to disown a command in the busybox shell?
I'm trying to write a quick-and-dirty shell script daemon to run on a home router that has a busybox shell, which doesn't support disown. Is there any way to do either of the following?
Run a command ...
0
votes
0
answers
176
views
Can't restart a suspended process
I execute a long running Python-process. To stop the annoying noise from the fans I use AppPolice to prevent this process from using more than 20 % CPU (I don't care when it finishes).
I think that ...
0
votes
1
answer
97
views
Why does Unix background process termination line not print right after termination?
So as an example if I run:
sleep 1 & sleep 2 & sleep 3
I will immediately get the process IDs e.g.
[1] ...
[2] ...
and then the shell freezes until the sleep 3 finishes running and then ...
0
votes
1
answer
226
views
Reasons for stty -tostop having no effect [duplicate]
I am trying to get a background process to print to the terminal. I haven't seen anything that otherwise indicates there is anything else to do besides stty -tostop. Am I missing something? Running ...
1
vote
2
answers
877
views
Does any terminal multiplexer (screen, tmux, zellij) support job suspension (Ctrl-Z) in Bash?
As far as I've seen, pressing Ctrl-Z on any terminal multiplexer, or trying to start them in the background, does nothing or crashes.
I know that, in a sense, terminal multiplexers are a "...
0
votes
2
answers
2k
views
How to write a process that restart again every time that it's killed
I want the exact opposite of this question. I want to know how I can create a process that keeps restarting if it's killed. Could someone give me an implementation example?
For instance, let's assume ...
0
votes
0
answers
126
views
Unmount user home directory in a delayed background process after logging out
The home directory of user bob is mounted by a superuser from elsewhere.
bob himself is a sudoer, he is logged in and is happily using his mounted home directory. He finishes his work and wants to run ...
29
votes
2
answers
6k
views
Why does "yes&" crash my Bash session?
"Yes, and..." is a wonderful rule-of-thumb in improvisational comedy. Not so much in the UNIX world.
When I run the admittedly silly yes& command, I cannot interrupt it. The terminal ...
2
votes
2
answers
4k
views
What is the "correct" way to run a systemd service which spawns long running detached processes?
I have a systemd service which spawns an ffmpeg process any time it detects a new event. These processes are meant to survive and run to completion even if the service is restarted (hence them being ...
-1
votes
1
answer
241
views
Strange mysqld process on my system wont let port 3306 be free
I am using ubuntu Jammy release and on my system port no 3306 is unusable since I tried ssh based port forwarding on the same to a different machine. Also while running ps -aux it shows a strage ...
2
votes
2
answers
713
views
Bash wait command actually gets result from background job cache, would the cache cause memory leak when it creates background jobs continuously?
I was checking possibilities of pid leaks about a bash script which continuously create background jobs yet not call wait command, I happened found (by strace) that Bash monitors SIGCHLD and ...
0
votes
1
answer
633
views
How can I have "names" for my background processes (not just the command)?
I run a lot of vim windows, and often put them in the bg. The problem is that they all say vim when I list jobs so it's hard to distinguish.
[1] - suspended nvim
[2] - suspended nvim
[3] + ...
0
votes
1
answer
453
views
Writing a ksh-script with a predefined time-out
My OS is AIX (7.2) and my shell is ksh88 (preferably) or ksh93, if necessary.
I want to write a script that sets some maximum timer for its execution. If it manages to finish its task within this time ...
1
vote
1
answer
135
views
Does POSIX sh require expanding $! in order to keep a reference to the child process?
Spec
According to this online POSIX Spec, in Shell & Utilities, Shell Command Language, Section 2.9.3 Lists has the following to say about Asynchronous Lists:
When an element of an asynchronous ...
0
votes
1
answer
213
views
Is it possible to defer reaping of background processes in bash?
If I just run sleep 1 & in bash, the sleep process will get reaped almost instantly after it dies. This happens whether job control is enabled or disabled. Is there a way I can make bash hold off ...
1
vote
2
answers
211
views
Is there a performance penalty for backgrounding a process?
If I do:
sleep 1
versus
sleep 1 & wait $!
will there be any difference in terms of CPU usage for spawning a foreground process versus a background process? Or will the performance of both lines ...
0
votes
1
answer
207
views
Sleep vs tail to wait on process
Currently I do:
while [ -d "/proc/$PID" ]; do
sleep 1
done
To wait for a process to exit. If I would replace it with:
tail --pid=$PID -f /dev/null
Would that be more efficient for the ...
0
votes
3
answers
127
views
bash -c "exec -a myProcessName ./script.sh &" doesn't send that script into backgound
From a bash script, I need to start three processes and put to each of these processes a name, in order to be able to stop them in a later stop command.
# Démarrer les applications eco emploi : ...
6
votes
2
answers
2k
views
bg command not sending process to background
After pausing the process with Ctrl+Z,
I attempted to send it to background with the bg command.
Unfortunately, the process isn't sent to the background,
and reappear to be running foreground.
Then, ...
1
vote
0
answers
149
views
Background process does not show up in ps
I used ssh to start a dotnet app as background job on a remote server
dotnet MyApp.dll &
I confirmed, that the app was running and then terminated the ssh session.
Now I want to kill this ...
0
votes
1
answer
101
views
Find out if a process was kicked off in the background or got backgrounded mid-run
I'm interested in Linux specifically, but an answer for other Unices would be great as well:
Does the system have a way of signaling to a process that it's been launched in the background? In other ...