Questions tagged [job-control]
Questions about the various ways jobs can be controlled by the shell: suspending, resuming, terminating execution etc.
216
questions
4
votes
0
answers
26
views
Name of background job started from EXIT trap is wrong
The following script:
#!/bin/bash
set -m
atexit() {
sleep 1 &
jobs
}
trap atexit EXIT
echo Hello world
Produces this output:
$ bash ./foo.sh
Hello world
[1]+ Running ...
1
vote
1
answer
33
views
Separate variable scope spawning commands under job control
Is is possible in bash - or other sh-derivative shell - to run in the foreground from command-line a list of commands that have their own variable scope (so any values assigned to variables in that ...
1
vote
0
answers
36
views
How to check whether a shell process has job-control enabled?
Is there a way to programmatically check whether a given (shell) process has job-control enabled?
0
votes
2
answers
50
views
Possible to pause console operation?
I have many working jobs running on different consoles.
They almost occupied all the CPU usage, which caused me hard to control the system ( very slow response time )
Is there any way to pause these ...
7
votes
0
answers
152
views
Bash script containing sudo - unreliable background resume (bg)
I have the following simple bash script (called test.sh), that shows disk usage in the root dir. sudo is needed to list all directories (and I'm not asked for sudo password).
#!/bin/bash
sudo du -h --...
3
votes
0
answers
37
views
Why do backgrounded commands in Zsh functions not show correctly in jobs?
In Bash 5.2, the output of jobs after either of the following is identical modulo job numbers:
sleep 3
# press C-z
s() { sleep 3; }
s
# press C-z
In both, jobs produces something like
[1]+ Stopped ...
1
vote
0
answers
53
views
Why bash for loop goes to stopped job when Ctrl+C is pressed?
Suppose I have a log file generated this way:
yes | head -n 1000000 > log
Now when I view it like this
for i in log; do cat $i; done | less -S
press Ctrl+C in less and quit it with q, some ...
2
votes
1
answer
104
views
Prevent Zsh from quitting if job in background
From man zsh, you can see:
If you [...] try to exit again, the shell will not warn you a second time; the suspended jobs will be terminated, and the running jobs will be sent a SIGHUP signal, if the ...
1
vote
3
answers
733
views
How to run a command in background job and wait for result in a bash script
How can I spawn a process for a particular command and while it is running capture its output?
For example I want to perform dd on a block and while it is doing its job and producing status message , ...
0
votes
1
answer
423
views
What exactly does it mean to run a process in the "background"?
I want to understand a little bit better, what a background process is. The question came to live as a result of reading this line of code:
/usr/sbin/rsyslogd -niNONE &
Source
The documentations ...
7
votes
3
answers
767
views
How to programmatically get the job id of a newly backgrounded process in Bash
In Bash, how do you programmatically get the job id of a job started with &?
It is possible to start a job in the background with &, and then interact with it using its job id with Bash ...
-5
votes
1
answer
294
views
in linux how to stop or suspend or hangup a job without using fg command or ctrl+z? [duplicate]
i am new on linux but i have an assignment and it requires to stop and suspend and hangup certain jobs without using the fg or ctrl+z commands like this picture and what does the dot after the number ...
3
votes
2
answers
231
views
How to merge data from multiple background jobs back to a single data stream in bash
I've run into a couple of similar situations where I can break a single-core bound task up into multiple parts and run each part as separate job in bash to parallelize it, but I struggle with ...
0
votes
1
answer
37
views
Is a pure number like "3" a valid jobspec?
I was reading a book about Linux. It states that to bring a process to foreground, use the fg command and a percent sign (%) followed by the job number. I did some testing and found that it works as ...
2
votes
2
answers
321
views
Call other process after executing a blocking process in shell
I have a process that is blocking in nature. It is executed first. In order to execute the second process, I moved the first process to the background and executed the second process. Using the wait ...
2
votes
0
answers
183
views
Why does foreground job ignore job control signals when Bash is running as PID 1?
When bash is invoked as pid 1 directly through the kernel option init=/bin/bash --login, it will issue something like this before prompting:
bash: cannot set terminal process group (-1): Inappropriate ...
1
vote
1
answer
167
views
How to kill all background and spawned processes of a bash script in its pre-exit handler?
I'm using the wait -n technique to perform max_jobs parallel tasks:
#!/usr/bin/env bash
cleanup() {
echo "cleaning up..."
}
trap "cleanup" EXIT
do_task() {
echo "...
3
votes
1
answer
2k
views
Reliable way to get PID of piped background process
I need to retrieve the PID of a process piped into another process that together are spawned as a background job in bash. Previously I simply relied on pgrep, but as it turns out there can be a delay ...
0
votes
1
answer
641
views
Does Crontab queue a job?
I have scheduled a crontab job for every 2 minutes. But I have recently started to notice that the program takes more time (approx 7-8 mins)to finish execution.
So does cron queues all the jobs that ...
0
votes
1
answer
946
views
Reboot and relaunch a script if error
I have a script (not written by me, I cannot modify it) that has to run for days, that sometimes fails (exits with an error).
In this case all I have to do is just reboot the server (there is no ...
0
votes
1
answer
252
views
Skip loop iteration(s) interactively on keypress
I am looping over an array and for each iteration, run a long during process, like this:
!#/bin/bash
arr=({1..100})
for i in "${arr[@]}"; do
echo "$i"
sleep 10
done
Now I ...
1
vote
1
answer
792
views
"kill %{job id}" vs "kill {job pid}"
I'm working with some tail -f path/to/my/log/file | grep pattern& and I need to kill the process as quick as possible.
With classic kill {tail PID}, tail still displays its buffer and it takes ...
0
votes
0
answers
606
views
Why set -m is not working? Giving me error job control is turned off!
I am trying to execute an entryscript for docker container. I have build this image from php-fpm alpine linux (7.3 version). Once the container is started it should execute some commands in prior, I ...
1
vote
0
answers
153
views
How to return a value from a job?
I want to spin up some jobs within a script to do some work in parallel. I will know when the work is done by counting the number of active jobs. The issue I'm having is that I want to also return a ...
0
votes
1
answer
49
views
How to kill jobs from a script that didn't clean them up
I have a script that started a job but didn't clean it up. The job is running in a loop in the background and I don't know which process it is and it's not listed in jobs. It's printing spam in my ...
27
votes
3
answers
2k
views
How can I prevent the second command in a chain while keeping the first one running?
Yesterday before going to sleep I started a long process of which I thought it would be finished before I stand up, therefore I used
./command && sudo poweroff
my system is configured to not ...
1
vote
1
answer
644
views
Configure zsh jobs output and fg behavior
Until recently I was pretty satisfied with how the fg and jobs command worked in my zsh, i.e.:
just fg -> foreground the most recently backgrounded job again
jobs -> display command name (incl. ...
1
vote
1
answer
273
views
'jobs' shows a no longer existing process as running
I'm running a long-running pipeline from bash, in the background:
find / -size +500M -name '*.txt' -mtime +90 |
xargs -n1 gzip -v9 &
The 2nd stage of the pipeline takes a long time to complete ...
1
vote
0
answers
537
views
How to suspend and resume processes from a script
I am trying to solve the problem given in
pause youtube-dl when network is disconnected and resume when it is connected again
To stop and resume process, I have taken guideline from How to suspend and ...
2
votes
2
answers
111
views
Does a program run by bash runs in a new job?
In this video, it is said that:
In the normal arrangement, if you open a terminal, and inside you have a shell running, that shell represents the start of a new session. That session starts with one ...
0
votes
0
answers
46
views
What happens when we put AND-LISTS to background?
I am trying to understand how shell manages process groups of members of AND-LISTS.
For example, Bash (and also dash) implements the following behavior:
p1 && p2 - processes p1 and p2 have ...
0
votes
0
answers
230
views
how to suspend a remote process started by: local-shell -> ssh -> remote bash -> remote-process
I have one, single terminal/channel to a remote system. I can use ssh to open Bash on that system and interact with it to invoke desired remote process. Due to some reason, the remote process is no ...
0
votes
0
answers
980
views
Understanding background processes and terminal process group id
I am reading the bash reference manual about Job control found here (emphasis mine):
To facilitate the implementation of the user interface to job control,
the operating system maintains the notion ...
3
votes
3
answers
164
views
Map shell job numbers to PIDs
I use shell job control to kick longer running tasks in to the background so I can continue while they churn through their data.
I can see the jobs I've got running with jobs, for example,
jobs
[2]- ...
1
vote
1
answer
274
views
Return to a particular job in the jobs list
If I have the following jobs running in a shell
-> % jobs -l
[1] 83664 suspended nvim
[2] 84330 suspended python
[3] 84344 suspended python
[4] 84376 suspended nvim
[5] - 84701 ...
6
votes
1
answer
1k
views
kill %1 equivalent in fish
In bash, if I run kill %1, it kills a backgrounded command in the current shell (the most recent one, I believe).
Is there an equivalent of this in fish? I haven't been able to find it online in a bit ...
2
votes
1
answer
1k
views
zsh: Why do I get suspended background processes even when I have `stty -tostop`?
I like my background processes to freely write to the tty. stty -tostop is already the default in my zsh (I don't know why, perhaps because of OhMyzsh?):
❯ stty -a |rg tostop ...
0
votes
2
answers
6k
views
Programmaticaly open new terminal with Bash and run commands, keeping job-control
In an X session, I can follow these steps:
Open a terminal emulator (Xterm).
Bash reads .bashrc and becomes interactive. The command prompt
is waiting for commands.
Enter vim 'my|file*' '!another ...
3
votes
1
answer
480
views
Shell: Make a command go into a separate process group
When using a job control capable shell, each pipeline is normally placed into its own process group.
When spawning a sub-process from an interactive program, such as an editor, the sub-process will ...
0
votes
1
answer
1k
views
Why does my process terminate upon log out despite nohup and disown?
I have an executable (a server made with Unity) which I want to continue to run after I log out. All the interwebs say that I should be able to accomplish this with nohup or disown or both. But it ...
0
votes
1
answer
167
views
Arch linux arm proot installation on android cannot set terminal process group (bash) and no job control in shell
Recently on my android device I installed Arch via proot on termux but when I run the installation and enter bash it tells me that it cannot set the terminal process group and that it has no control ...
2
votes
2
answers
336
views
less stops my script; why is that and how to avoid?
I have this Bash script named as s in current directory:
#!/bin/bash
pipe_test() {
( set -m; (
$1
); set +m ) |
(
$2
)
}
pipe_test "$1" "$2"
If I call e.g.
./s yes ...
0
votes
0
answers
194
views
zsh bug: Unexpected process suspension
Update: simpler reproduction
mdoc-test () {
sleep 0 | sleep 0
cat
}
echo start |VISUAL=vim command vipe|mdoc-test
# zsh: suspended (tty output)
Posted to zsh mailing list.
mdoc-test () {
...
0
votes
0
answers
25
views
Is there a way to print a snapshot of a job that's in the background to standard output? [duplicate]
If I have a job that's running/paused in the background, is there a way of printing a snapshot of its activity to standard output?
1
vote
3
answers
544
views
How to use one terminal with multiple interactive jobs without stopping them?
I have two shell-scripts, say client.sh and server.sh, which has to work simultaneously and give some useful output in watch-way.
And I am able to use only one terminal. So I should switch between ...
0
votes
0
answers
174
views
Background process in a shell script?
I wanted to find a way to run Spock tests in headless mode.
One solution I found involves running these two commands:
Xvfb :99 &>/dev/null &
export DISPLAY=:99
This works.
I am not sure ...
1
vote
1
answer
148
views
How does bash `auto_resume` job control variable works?
Chapter 7.3 Job Control Variables in Bash Reference Manual has the following description about auto_resume variable:
auto_resume
This variable controls how the shell interacts with the user ...
0
votes
0
answers
27
views
Alias problems with inline job control [duplicate]
I am having a problem with the following:
Alias:
alias gks='gitk --all &; clear; git status'
When I try it I see -
Console Resp:
$ gks
bash: syntax error near unexpected token `;'
...
1
vote
2
answers
62
views
How to ensure child background processes terminate when using `set -e`?
set -e
while true; do echo "test"; sleep 1; done &
echo "done"
ueoa
If I run this, once it reaches ueoa (a random command that does not exist), it'll 'terminate' but keep the while true; do ...
0
votes
0
answers
6k
views
/usr/bin/fg: line 4: fg: no job control
I have faced the problem mentioned above when I call
sleep 100 &
Background job starts, and then I pause the process by:
kill -STOP <PID>
Then if I just say
fg sleep
It brings the job ...