Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [job-control]

Questions about the various ways jobs can be controlled by the shell: suspending, resuming, terminating execution etc.

Filter by
Sorted by
Tagged with
2 votes
1 answer
51 views

Is there a way to `exec` a pipeline or exit shell after launching a pipeline?

I'm writing a shell wrapper script that is supposed to act as a pager (receiving input on stdin and performing output on a tty). This wrapper prepares environment and command lines, then launches two ...
intelfx's user avatar
  • 5,466
0 votes
1 answer
48 views

SIGTSTP(Ctrl-Z) not working for script started by script command

Note: script refers to the script command, which logs stdin and stdout to files. I was trying to run a script with the script utility to save output for later inspection while preserving text colors ...
GoDaft WithEBK's user avatar
0 votes
2 answers
81 views

Add a process to an already executing process? Like && or so

This question inspired me to another related question. Imagine that you start % nohup a.sh & and then want b.sh to execute when a.sh is finished (E.g., b.sh will process the output from a.sh. ...
d-b's user avatar
  • 1,947
0 votes
0 answers
32 views

linux: kill -9 process success only on second attempt

I'm currently solving umount /chrootedpath /dev/pts after several chroot(s): target is busy. I've found part of the problem - two processes still running ps had shown as sudo choot command. They were ...
Alex Martian's user avatar
  • 1,065
0 votes
0 answers
28 views

how to put an existing process into an interactive shell's foreground [duplicate]

Say I started a long running process with nohup. As predicted, I close the current shell session. I open a new one and then I would like to add the still running process to the foreground (or to the ...
Sebastian Carlos's user avatar
5 votes
3 answers
917 views

How to cleanup on suspense (ctrl-z) in a Bash script?

I have the following script: suspense_cleanup () { echo "Suspense clean up..." } int_cleanup () { echo "Int clean up..." exit 0 } trap 'suspense_cleanup' SIGTSTP trap '...
Sebastian Carlos's user avatar
1 vote
2 answers
539 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 "...
Sebastian Carlos's user avatar
28 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 ...
Sebastian Carlos's user avatar
1 vote
1 answer
80 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 ...
D. Ben Knoble's user avatar
1 vote
1 answer
269 views

How does bash recognize background child processes launched by a foreground process (script) on receiving Ctrl-C

My question has nothing to do with WCE (wait and cooperative exit). Assuming i have a script launched in an interactive shell (bash) as a foreground job: #! /bin/bash # script name: foreback.sh sleep ...
demonshunter's user avatar
6 votes
2 answers
1k views

bg command not sending process to background

After pausing the process with ctrl-z, I attempted to send it to background with bg command. Unfortunately, the process isn't sent to the background, and reappear to be running foreground. Then, I do ...
Faxopita's user avatar
  • 179
4 votes
0 answers
60 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 ...
Tavian Barnes's user avatar
1 vote
1 answer
68 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 ...
S P Arif Sahari Wibowo's user avatar
2 votes
1 answer
431 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?
ivan's user avatar
  • 1,888
0 votes
2 answers
109 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 ...
Mark K's user avatar
  • 905
9 votes
1 answer
310 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 --...
Artur Meinild's user avatar
4 votes
0 answers
149 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 ...
D. Ben Knoble's user avatar
1 vote
0 answers
87 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 ...
ks1322's user avatar
  • 1,656
3 votes
1 answer
668 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 ...
ange's user avatar
  • 33
2 votes
3 answers
2k 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 , ...
DEKKER's user avatar
  • 968
0 votes
1 answer
2k 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 ...
Andrew Savinykh's user avatar
10 votes
3 answers
2k 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 ...
illabout's user avatar
  • 419
-5 votes
1 answer
597 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 ...
ahmad naser's user avatar
3 votes
2 answers
300 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 ...
guest's user avatar
  • 77
0 votes
1 answer
99 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 ...
Fajela Tajkiya's user avatar
2 votes
2 answers
794 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 ...
ravi's user avatar
  • 143
2 votes
0 answers
244 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 ...
Li-Guangda's user avatar
1 vote
1 answer
284 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 "...
Zeta.Investigator's user avatar
3 votes
1 answer
5k 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 ...
emike's user avatar
  • 53
0 votes
1 answer
1k 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 ...
StanGeo's user avatar
  • 101
0 votes
1 answer
2k 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 ...
Basj's user avatar
  • 2,559
0 votes
1 answer
632 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 ...
pLumo's user avatar
  • 22.7k
1 vote
1 answer
2k 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 ...
Maskim's user avatar
  • 63
0 votes
0 answers
1k 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 ...
astrosixer's user avatar
1 vote
0 answers
225 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 ...
Zhro's user avatar
  • 2,709
0 votes
1 answer
73 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 ...
Zhro's user avatar
  • 2,709
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 ...
Max Matti's user avatar
  • 523
2 votes
1 answer
1k 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. ...
maxschlepzig's user avatar
  • 57.9k
1 vote
1 answer
466 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 ...
arielf's user avatar
  • 890
1 vote
0 answers
857 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 ...
Ahmad Ismail's user avatar
  • 2,738
2 votes
2 answers
142 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 ...
YoavKlein's user avatar
  • 372
0 votes
0 answers
48 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 ...
gadm's user avatar
  • 11
0 votes
0 answers
310 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 ...
Julian Baczynski's user avatar
3 votes
0 answers
2k 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 ...
Moha the almighty camel's user avatar
3 votes
3 answers
186 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]- ...
Chris Davies's user avatar
2 votes
1 answer
571 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 ...
baxx's user avatar
  • 254
9 votes
2 answers
2k 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 ...
k_g's user avatar
  • 193
3 votes
1 answer
2k 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 ...
HappyFace's user avatar
  • 1,620
1 vote
2 answers
13k 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 ...
Quasímodo's user avatar
6 votes
1 answer
1k 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 ...
user1254127's user avatar

1
2 3 4 5