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 [job-control]

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

1
vote
0answers
20 views

Why does my job control fail inside a loop? [duplicate]

My bash script is supposed to start a process (let's say, run less) and bring it back to foreground every time the process is suspended (e.g. by pressing CTRL-Z). If I just keep repeating the ...
1
vote
1answer
26 views

Output of a command going in background on Mac

I have an issue on my Mac. HQSML-1584960:puppet rmoham860$ git diff [2]+ Stopped git diff HQSML-1584960:puppet rmoham860$ jobs -l [1]- 37022 Stopped (tty output): 22git diff [2]+ ...
1
vote
1answer
44 views

Does a shell which does not support job control has the concept of foreground and background processes?

I used to think that only if a shell supports job control, can it has the concept of "foreground" and "background" processes (group). But I read a paragraph indicating that's not true. From APUE § 10....
1
vote
0answers
29 views

List all jobs in all shell sessions (not just the current shell), by current user

I know that the jobs command only shows jobs running in current shell session. Is there a bash code that will show jobs across shell sessions (for example, jobs from another terminal tab) for ...
6
votes
4answers
357 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 ...
3
votes
2answers
46 views

How to wrap a command such that its execution is throttled (that is, it executes at most once every X minutes)

I'm interested in wrapping a command such that it only runs at most once every X duration; essentially, the same functionality as the lodash throttle function. I'd basically like to be able to run ...
3
votes
1answer
45 views

Can I make a process become a job of a bash process?

Given an interactive bash process and a process which wasn't started from the bash process, is there some way (program) which can make the process a job of the shell? This may sound impossible, but ...
1
vote
1answer
23 views

Behavior of directly vs indirectly backgrounded children on read

When I do ( sleep 1; read x ; echo x=$x; echo done ) & then with the default terminal settings, the job gets stopped by SIGTTIN. If I do ( ( sleep 1; read x ; echo x=$x; echo done ) & ) ...
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 ...
-2
votes
2answers
49 views

Does an interactive bash process implicitly send any signal other than SIGHUP to its job?

Does an interactive bash process implicitly send any signal other than SIGHUP to its job? By implicitly, I mean not as a consequence of a user's request to send a signal to a job. It helps to answer ...
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 ...
1
vote
0answers
59 views

Program start from interactive shell fails when shell script initiated by launcher

[This post has been edited from the original text to add the results of further investigation and get to the point more quickly -- Thanks @ctrl-alt-delor] Why does this script: #!/bin/bash read -p "...
12
votes
5answers
824 views

How to plan a task to run after another already running task in bash? [duplicate]

I'm looking for something like command1 ; command2 i.e. how to run command2 after command1 but I'd like to plan execution of command2 when command1 is already running. It can be solved by just typing ...
1
vote
0answers
40 views

Killing a process when some other process is finished

Given a | b, i'd like to kill b when a is finished. b is an interactive process, which doesn't terminates when a is finished (fzf in my case), and the whole a | b is executed in a $() subshell. So ...
0
votes
1answer
34 views

cron doesn't execute scripts after setting it up

According to this site I set up cron to execute a script for me, first just trying to get it to work with cat before doing the actual work I need to do (actual work will need root priviliges so I did ...
5
votes
2answers
161 views

Process killed before being launched in background

I'm using a bash script script.sh containing a command cmd, launched in background: #!/bin/bash … cmd & … If I open a terminal emulator and run script.sh, cmd is properly executed in background, ...
0
votes
1answer
67 views

Bash interactive shell hangs when Tmux is suspended if it was automatically started by Bash startup file

When I manually start Tmux by issuing tmux from my Bash interactive shell I can later suspend Tmux with CTRL-BZ without problems. Pressing this key combination brings me back to the parent process, i....
-1
votes
1answer
53 views

How can I see the processes structured by sessions and process groups?

As far as I know, linux kenerl has sessions and process groups concept, I want to see the sessions and groups, what should I do?
0
votes
2answers
161 views

How can I run multiple pv commands in parallel?

I want to run a sequence of command pipelines with pv on each one. Here's an example: for p in 1 2 3 do cat /dev/zero | pv -N $p | dd of=/dev/null & done The actual commands in the pipe don't ...
-4
votes
1answer
54 views

Does `wd:` in `jobs` show the current working directory of each job, or the previous working directory when invoking each job?

Does wd: in jobs show the current working directory of each job, or the previous working directory when invoking each job? Can you demonstrate it or quote from some references? I was under the ...
0
votes
1answer
69 views

How can I bring a background GUI job to the front of my desktop?

In Lubuntu 18.04, I have many background GUI jobs running in a bash shell. Among them, I have a evince process running in background: $ jobs | grep evince [29] Running evince ...
0
votes
0answers
444 views

Shell: send foreground process to background without suspending it? [duplicate]

I have a command I'm running in the background, fnordctl & Occasionally I pull it up into the foreground, fg Now, I'd like to send it back to the background to continue running. Typing Ctrl-z ...
2
votes
1answer
120 views

How to start Vim from a trap and still be able to resume it after suspending it?

I have the following code in my ~/.zshrc: nv() ( if vim --serverlist | grep -q VIM; then if [[ $# -eq 0 ]]; then vim elif [[ $1 == -b ]]; then shift 1 IFS=' ' vim --...
0
votes
1answer
49 views

Monitor Process Output For Scripts

Is there a way to view the console outputs of a particular script that is running in the background on a machine? Maybe using the pid or something similar. For example, to view the output of this ...
2
votes
1answer
90 views

How does bash's job control handle stopped or terminated background jobs?

While studying the internals of bash's job control mechanism under Linux I have came across a little problem of understanding. Let's assume the following scenario: script is executed in background ...
7
votes
1answer
281 views

Stopped (ctrl z) process will not restart, and no longer in job list

I was running apt upgrade, when I needed the terminal, so did a ctrlz. When I tried to restart it (fg), it would not restart, because it was no-longer in the jobs list (jobs). (I Did not, run disown). ...
10
votes
1answer
164 views

How can I cancel the rest of a list of commands in Bash?

In Bash, occasionally I will type in a list of commands and hit Enter, and only later realize that there is a mistake with some command near the end of the list. I know that if I press Ctrl+C it will ...
1
vote
1answer
46 views

Killing jobs started within functions

I'm trying to use some functions in a bash script to simplify calling some child processes. I want to decide at the call site whether or not to run the process in the background as a job, or in the ...
0
votes
3answers
129 views

Get process information (the command, etc) from pid

I have this code: for job in `jobs -p`; do code=0; wait ${job} || code=$? if [[ "${code}" != "0" ]]; then echo "At least one job failed with exit code =>...
5
votes
3answers
4k views

How to run multiple background jobs in linux?

I have a basic understanding of how to get a job in foreground switch to background and vice-versa but I am trying to come up with a way so that I can run multiple jobs in the background.I tried to ...
3
votes
0answers
30 views

Log background jobs started in all the manually started shells?

Sometimes I accidentally killed all the background jobs in a shell, for example, because The window of a Window's program running under Wine is not in the front by default. I know I can use ...
3
votes
1answer
69 views

Assign job number to background process by hand

Let's say I send two jobs to the background. $ sleep 77 & $ sleep 99 & Then I check my jobs $ jobs > [1] - running sleep 77 > [2] + running sleep 99 Can I control what job ...
0
votes
1answer
279 views

Is the “kill” command for job control the same as the “kill” command to send a signal to a process?

In Linux, you can do the following: kill 1 (or kill %1) Which means "close the processes in job number 1". And you can do the following: kill 1234 Which means "send the SIGTERM signal to the ...
2
votes
0answers
141 views

Shell job-control: possible to “rename” a running job?

In the shell (I'm using Bash), I frequently use Ctrl-Z and fg to suspend one job and foreground another. An example would be suspending a running instance of Vim and foregrounding a previously ...
1
vote
0answers
33 views

Mass killing stale backgrounded jobs

$ jobs [1] Stopped emacsclient -nw components/frontend/app/views/frontend/dashboard/index.html.erb [2] Stopped emacsclient -nw components/frontend/app/views/...
3
votes
4answers
6k views

How to kill all jobs in bash?

So, I have some jobs like this: sleep 30 | sleep 30 & The natural way to think would be: kill `jobs -p` But that kills only the first sleep but not the second. Doing this kills both processes:...
1
vote
1answer
75 views

why does kill work differently on job numbers than PIDs?

I was trying to demonstrate job control to a friend, when I ran into an unexpected behaviour. For certain commands, kill works with the job number, but not with the process ID. An example of the ...
3
votes
2answers
1k views

Is it possible to use commands like `fg` in a shell-script?

I am trying to create a fun Terminal Screensaver which consists of the cmatrix package (one that turns terminal in one similar to the movie The Matrix) and xprintidle to determine idle time of the ...
7
votes
3answers
1k views

Background, zombie, daemon and without ctty - are these concepts connected?

How these process concepts are related together - background, zombie, daemon and without controlling terminal? I feel that they are somehow close, especially through the concept of controlling ...
1
vote
1answer
2k views

What does “fg” stand for?

There is no manual entry for ctrl-z or fg. What does "fg" stand for in the context of job control? In other words, typing ctrl-z will suspend the current job drop me back into the shell, and the ...
1
vote
1answer
262 views

bash function that sends email after job is finished

I have written following function in my bashrc. It checks if a job is running every 5 seconds and sends email when job is finished. function jobcheck () { time=`date` jobstatus=`jobs $1` while [...
3
votes
1answer
525 views

Kill job in subshell with set -m

I have the following bash script: #!/bin/bash set -m ( (bin/pnvd &> /dev/null; kill 0) & sleep 2 perl integration-test/fuzz-test.pl || kill 0 kill %1 ) The first three ...
0
votes
0answers
29 views

Timed stopping and restarting of a a process [duplicate]

I am running a huge base backup to a cloud server that will take a few days to complete. When it is running it takes most of my internet connection. It is running in a terminal, so I can manually ...
1
vote
1answer
169 views

Cannot recover from sleeping tmux during SSH session

I've tried searching this on google but have been very unsuccessful so I've resorted to trying to get someone's help with this. On my local machine I do the following: $ tmux CTRL+b CTRL+z $ fg and ...
1
vote
0answers
81 views

How to run GDB in backround and bring it back?

I'm writing bash scripts that launch a test scenarios: several programs that connect to each other. If something crashed, I'd like to have a GDB command line. Looks something like that: myprogram &...
0
votes
0answers
75 views

jobs command gives wrong output

I'm using Red Hat 6, and typing jobs gives me: [2] + 12511 12510 Running find . | xargs grep -i "string" >../a.txt Those pids don't exist, and typing fg %2 outputs: ...
1
vote
0answers
27 views

Create a file at time 't' after PBS job execution begins

I submit a PBS job for 02:00:00 hours. I need to create a file in the PBS working directory at a specified time t (say 01:30:00 hours) after the job has begun to ensure that the job terminates ...
3
votes
1answer
1k views

Clean way to bring back background process to foreground in shell script

As an example: I have working shell script which starts up weblogic (which will continue to run) and then do deployment At the end I bring background process back to foreground, so that shell script ...
2
votes
1answer
30 views

Force a process to ignore/discard accumulated input while suspended?

So I've got an SSH reverse tunnel open, and I'm using tail to pipe the output of the sshd log into awk to detect certain login events and trigger an action. It looks like this: ssh -NR 2222:127.0.0.1:...
1
vote
1answer
46 views

prevent “[1] + done $scriptname” and “[1] 31303” to be shown

I have set up an alias for my mutt: alias mutt='$HOME/.mutt/run-notmuch-offlineimap & ; mutt'. Note: Changing my Alias to alias mutt='$HOME/.mutt/run-notmuch-offlineimap 2> /dev/null & ; ...