Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
6
votes
1
answers
2174
views
Please explain the output from the jobs command
When I ran `jobs` command I see the following output : [1] - Suspended ./startWebLogic.sh [2] + Suspended (signal) top 1. What does -/+ indicate in the second column ? 2. What is the difference between Suspended and Suspended(signal) ?
When I ran
jobs
command I see the following output :
- Suspended ./startWebLogic.sh
+ Suspended (signal) top
1. What does -/+ indicate in the second column ?
2. What is the difference between Suspended and Suspended(signal) ?
Geek
(6868 rep)
Jan 21, 2013, 05:18 PM
• Last activity: May 26, 2025, 09:42 AM
0
votes
2
answers
783
views
How do I submit SAS jobs in batch mode?
I am using [SAS](https://www.sas.com/en_gb/home.html), an analytics software package for Unix (amongst others). I am connecting to my Unix system with PuTTY. I want to submit 10 sas programs via putty. My requirement is that each job should run in a sequence (ex: 2nd job should run after 1st job, 3r...
I am using [SAS](https://www.sas.com/en_gb/home.html) , an analytics software package for Unix (amongst others). I am connecting to my Unix system with PuTTY.
I want to submit 10 sas programs via putty. My requirement is that each job should run in a sequence (ex: 2nd job should run after 1st job, 3rd job should run after completion of 2nd job) and also if there is any error in job complete running process should stop (ex: if there was an error in second job then 3rd job should not run.)
Currently I am submitting jobs as shown below, but the problem is that all of the jobs are started at the same time; I need one at a time as explained above.
x sasb -sv sas92 code1.sas;
x sasb -sv sas92 code2.sas;
x sasb -sv sas92 code3.sas;
The
x
command here is [how to run a Unix command from within SAS](https://support.sas.com/documentation/cdl/en/hostunx/61879/HTML/default/viewer.htm#a000290413.htm) . sasb
is the name of the command that I am running that way, which seems to be running all jobs simultaneously.
naveen p
(1 rep)
Feb 28, 2018, 01:50 PM
• Last activity: Sep 19, 2024, 04:25 AM
4
votes
1
answers
211
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 sleep 3 ``` --- In Zsh 5.9 (x86_64-apple-darwin20.6.0), the first produces simi...
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
+ Stopped sleep 3
---
In Zsh 5.9 (x86_64-apple-darwin20.6.0), the first produces similar enough output containing the sleep
command:
+ suspended sleep 3
The second produces almost useless output:
+ suspended
---
I have [lots of functions that invoke Vim with different arguments or completions](https://github.com/benknoble/Dotfiles/blob/854f9498cb90af3b84cb961a9e97cf0009970f31/links/zsh/vim.zsh) ; suspending Vim during the execution of any of them via C-z
or :suspend
puts such a useless entry in jobs
. It's not uncommon for me to have 2 or more such jobs, in which case it is rather difficult to keep them straight.
Why does Zsh do this and is there a way for me to fix it?
D. Ben Knoble
(552 rep)
Nov 15, 2022, 06:38 PM
• Last activity: Jul 26, 2024, 03:16 PM
6
votes
1
answers
999
views
Why does 'jobs' always return a line for finished processes when run in a subshell within a script?
Normally, when a job is launched in the background, `jobs` will report that it is finished the first time it is run after the job's completion, and nothing for subsequent executions: $ ping -c 4 localhost &>/dev/null & [1] 9666 $ jobs [1]+ Running ping -c 4 localhost &> /dev/null & $ jobs [1]+ Done...
Normally, when a job is launched in the background,
jobs
will report that it is finished the first time it is run after the job's completion, and nothing for subsequent executions:
$ ping -c 4 localhost &>/dev/null &
[1] 9666
$ jobs
[1] + Running ping -c 4 localhost &> /dev/null &
$ jobs
[1] + Done ping -c 4 localhost &> /dev/null
$ jobs ## returns nothing
$
However, when run in a subshell within a script it seems to always return a value. This script will never exit:
#!/usr/bin/env bash
ping -c 3 localhost &>/dev/null &
while [[ -n $(jobs) ]]; do
sleep 1;
done
If I use tee
in the [[ ]]
construct to see the output of jobs
, I see that it is always printing the Done ...
line. Not only once as I expected but, apparently, for ever.
What is even stranger is that running jobs
within the loop causes it to exit as expected:
#!/usr/bin/env bash
ping -c 3 localhost &>/dev/null &
while [[ -n $(jobs) ]]; do
jobs
sleep 1;
done
Finally, as pointed out by @muru, the first script works as expected and exits if run from the commandline:
$ ping -c 5 localhost &>/dev/null &
[1] 13703
$ while [[ -n $(jobs) ]]; do echo -n . ; sleep 1; done
...[1] + Done ping -c 5 localhost &> /dev/null
$
This came up when I was answering a question on Super User so please don't post answers recommending better ways of doing what that loop does. I can think of a few myself. What I am curious about is
1. Why does jobs
act differently within the [[ ]]
construct? Why will it always return the Done...
line while it doesn't when run manually?
2. Why does running jobs
within the loop change the behavior of the script?
terdon
(251585 rep)
Mar 24, 2015, 11:23 AM
• Last activity: Jun 11, 2024, 05:51 PM
6
votes
2
answers
1294
views
Why is subshell created by background control operator (&) not displayed under pstree
I understand that when I run `exit` it terminates my current shell because `exit` command run in the same shell. I also understand that when I run `exit &` then original shell will not terminate because `&` ensures that the command is run in sub-shell resulting that `exit` will terminate this sub-sh...
I understand that when I run
exit
it terminates my current shell because exit
command run in the same shell. I also understand that when I run exit &
then original shell will not terminate because &
ensures that the command is run in sub-shell resulting that exit
will terminate this sub-shell and return back to original shell. But what I do not understand is why commands with and without &
looks exactly the same under pstree
, in this case sleep 10
and sleep 10 &
. 4669 is the PID of bash under which first sleep 10
and then sleep 10 &
were issued and following output was obtained from another shell instance during this time:
# version without &
$ pstree 4669
bash(4669)───sleep(6345)
# version with &
$ pstree 4669
bash(4669)───sleep(6364)
Should't the version with &
contain one more spawned sub-shell (e.g. in this case with PID 5555), like this one?
bash(4669)───bash(5555)───sleep(6364)
PS: Following code was omitted from output of pstree
beginning for better readability:
systemd(1)───slim(1009)───ck-launch-sessi(1370)───openbox(1551)───/usr/bin/termin(4510)───bash(4518)───screen(4667)───screen(4668)───
Wakan Tanka
(825 rep)
Jan 20, 2016, 10:22 PM
• Last activity: May 30, 2024, 06:33 AM
4
votes
1
answers
4009
views
What's the difference between a "job" and a "service" to systemctl?
What's the difference between a "job" and a "process" "service" wrt these two `systemctl` commands? ``` root@linuxbox:~# systemctl list-jobs No jobs running. ``` ``` root@linuxbox:~# systemctl list-units --type=service --state=running UNIT LOAD ACTIVE SUB DESCRIPTION containerd.service loaded active...
What's the difference between a "job" and a "process" "service" wrt these two
systemctl
commands?
root@linuxbox:~# systemctl list-jobs
No jobs running.
root@linuxbox:~# systemctl list-units --type=service --state=running
UNIT LOAD ACTIVE SUB DESCRIPTION
containerd.service loaded active running containerd container runtime
docker.service loaded active running Docker Application Container Engine
getty@tty1.service loaded active running Getty on tty1
inetd.service loaded active running Internet superserver
ntp.service loaded active running Network Time Service
rngd.service loaded active running Start entropy gathering daemon (rngd)
serial-getty@ttyPS0.service loaded active running Serial Getty on ttyPS0
ssh.service loaded active running OpenBSD Secure Shell server
syslog-ng.service loaded active running System Logger Daemon
tftpd-hpa.service loaded active running LSB: HPA's tftp server
watchdog.service loaded active running watchdog daemon
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
11 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
StoneThrow
(1937 rep)
May 7, 2021, 06:42 PM
• Last activity: Jan 8, 2024, 11:15 PM
3
votes
1
answers
947
views
Key binding to swap shell foreground/background jobs
In spite of heavy `tmux` use and switching between panes, I still frequently find myself using shell job control. When something needs poking I'll background the tool I'm using with Ctrl + Z , poke the thing, then `fg` the tool again. The issue is sometimes the "poking" turns into using another tool...
In spite of heavy
tmux
use and switching between panes, I still frequently find myself using shell job control. When something needs poking I'll background the tool I'm using with Ctrl+Z, poke the thing, then fg
the tool again. The issue is sometimes the "poking" turns into using another tool and I want to go back and forth a couple times.
Would it be possible to bind another key that is trapped by the shell (i.e. not ever passed though to a foreground app) that backgrounds the current job and foregrounds whatever the most recent background job is?
Caleb
(71790 rep)
Oct 25, 2019, 03:50 PM
• Last activity: Nov 19, 2023, 07:23 PM
11
votes
1
answers
10150
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 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 current user?
xxx374562
(314 rep)
Mar 28, 2019, 06:56 AM
• Last activity: Sep 5, 2023, 03:51 PM
29
votes
2
answers
5674
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 crashes or gets stuck into a loop. I expect the `yes` process to be suspended immediately, since any process in the...
"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 crashes or gets stuck into a loop.
I expect the yes
process to be suspended immediately, since any process in the background should suspend if attempting to write to stdout, but it doesn't seem to be the case, and I'm wondering why.
Sebastian Carlos
(262 rep)
Jul 6, 2023, 07:17 AM
• Last activity: Jul 7, 2023, 04:45 PM
4
votes
1
answers
1140
views
Making zsh jobs -p behave as in bash
Is there a way to make `jobs -p` in zsh behave as in bash, ie. give _only_ a number, such that one can do `kill $(jobs -p)`?
Is there a way to make
jobs -p
in zsh behave as in bash, ie. give
_only_ a number, such that one can do kill $(jobs -p)
?
Toothrot
(3705 rep)
Jan 8, 2019, 11:12 PM
• Last activity: Jun 28, 2023, 04:12 PM
0
votes
1
answers
88
views
Why are commands reading from /dev/stdin get a status "[1]+ Stopped" when sent to background?
I have tried running the following commands: - `cat` - `base64 /dev/stdin` - `md5sum /dev/stdin` - `tail /dev/stdin` In all cases when I do: ``` ^Z $ bg $ jobs ``` I get the status: `[1]+ Stopped` instead of `[1]+ Running`. But if I read from a pipe then the job is considered running: ``` mkfifo /tm...
I have tried running the following commands:
-
cat
- base64 /dev/stdin
- md5sum /dev/stdin
- tail /dev/stdin
In all cases when I do:
^Z
$ bg
$ jobs
I get the status: + Stopped
instead of + Running
.
But if I read from a pipe then the job is considered running:
mkfifo /tmp/fifo1
cat /tmp/fifo1
^Z
$ bg
$ jobs
# + Running tail /tmp/fifo1 &
Why reading from /dev/stdin
makes a command to be considered as Stopped
when sent to background?
Marinos An
(889 rep)
Mar 28, 2023, 08:03 PM
• Last activity: May 26, 2023, 06:59 AM
0
votes
1
answers
580
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] + suspended nvim ``` One way around this is to open a specific file when starting vim: ``` nvim ./myfile...
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.
- suspended nvim
- suspended nvim
+ suspended nvim
One way around this is to open a specific file when starting vim:
nvim ./myfile
jobs
:
+ suspended nvim myfile
But this is a poor substitute for a name.
Another option is to (mis)use env vars like this to name the buffer:
vim name=my_name
But the output of jobs
could be more usable, and has the disadvantage of needing to preparing for the possibly unneeded backgrounding of the process at the moment of staring the process.
- suspended nvim name=my_name
+ suspended nvim name=other_name
Ideally I'd like to be asked to give the process an optional name when I press ctl-z
. Perhaps there's a plugin out there that handles this, but I haven't found it.
I would consider writing it myself, but I wouldn't know where to start. Presumably by re-mapping ctl-z
to some other program? And maybe I'd have to write something that sites in front of fg
and jobs
as well to control the output...
Any suggestions for this?
pixelearth
(101 rep)
Apr 29, 2023, 02:49 PM
• Last activity: Apr 29, 2023, 08:01 PM
0
votes
1
answers
4545
views
Cron Job vs. Scheduler: Understanding the Differences and Use Cases
What are the key differences between a Cron job and a scheduler, and in what use cases is using one of these tools more appropriate than using the other?
What are the key differences between a Cron job and a scheduler, and in what use cases is using one of these tools more appropriate than using the other?
orchard
(3 rep)
Apr 21, 2023, 05:36 PM
• Last activity: Apr 21, 2023, 06:49 PM
6
votes
1
answers
1325
views
Why jobs lost when after reconnect ssh?
I have a job that runs in the background via ctrl + z and bg, and after reconnecting ssh I cannot find that job in the jobs command but can find it in ps grep. For now, I searched this and I get the tmux may be a better solution, however, I am still wondering why exit ssh will lose jobs in the jobs...
I have a job that runs in the background via ctrl + z and bg, and after reconnecting ssh I cannot find that job in the jobs command but can find it in ps grep. For now, I searched this and I get the tmux may be a better solution, however, I am still wondering why exit ssh will lose jobs in the jobs command. I've put that in the background, it should exist after reconnecting, Am I right?
https://unix.stackexchange.com/questions/29692/how-can-i-manage-jobs-after-i-disconnect-from-my-tty-ssh-session
Yang Xu
(103 rep)
Sep 30, 2022, 02:41 AM
• Last activity: Sep 30, 2022, 03:25 AM
3
votes
1
answers
2203
views
What signal do bg and fg send?
I know that `ctrl` + `z` changes a process from _foreground_ to _background_ - as **suspended** - through `SIGTSTP`. I am able to re-run that background suspended process through either `fg` or `bg` as required. **Question** * What signal do `bg` and `fg` send? Not sure if both send the same or are...
I know that
ctrl
+ z
changes a process from _foreground_ to _background_ - as **suspended** - through SIGTSTP
. I am able to re-run that background suspended process through either fg
or bg
as required.
**Question**
* What signal do bg
and fg
send?
Not sure if both send the same or are different.
I did realise there are no neither man fg
nor man bg
. And well, there is no information about the signals through fg --help
and bg --help
Manuel Jordan
(2108 rep)
May 12, 2022, 11:02 PM
• Last activity: Jul 16, 2022, 05:47 AM
0
votes
1
answers
6104
views
How to use jobs command and view results
I am using Ubuntu 14.04 and I am trying to view the list of running jobs using the jobs command yet there is no results shown and when I enter "man jobs" the shell responds that there is no such command available. am I doing the wrong way to view job list? and if so what would be the solution to it?
I am using Ubuntu 14.04 and I am trying to view the list of running jobs using the jobs command yet there is no results shown and when I enter
"man jobs" the shell responds that there is no such command available. am I doing the wrong way to view job list? and if so what would be the solution to it?
Tower
(489 rep)
May 23, 2015, 02:52 PM
• Last activity: May 30, 2022, 08:42 AM
14
votes
1
answers
9790
views
backgrounded job keeps stopping
I am seeing some strange behavior on my RHEL6 bash prompt. I often like to execute command lines that look like ... $ ./myscript > junk 2>&1 ... then hit Ctrl-Z and then execute ... $ bg $ tail -f junk blah blah blah blah blah blah blah blah But today for some reason I am see that my job stays "stop...
I am seeing some strange behavior on my RHEL6 bash prompt. I often like to execute command lines that look like ...
$ ./myscript > junk 2>&1
... then hit Ctrl-Z and then execute ...
$ bg
$ tail -f junk
blah blah blah blah
blah blah blah blah
But today for some reason I am see that my job stays "stopped" and is not "running".
$ uname -a
Linux myhost 2.6.18-371.11.1.el5 #1 SMP Mon Jun 30 04:51:39 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.5 (Tikanga)
$ ./myscript.sh > output-07-JUL-16.txt 2>&1
^Z
+ Stopped ./myscript.sh > output-07-JUL-16.txt 2>&1
$ bg
+ ./myscript.sh > output-07-JUL-16.txt 2>&1 &
$ jobs
+ Stopped ./myscript.sh > output-07-JUL-16.txt 2>&1
$ jobs
+ Stopped ./myscript.sh > output-07-JUL-16.txt 2>&1
The script I am running is nothing exotic ...
#!/bin/sh
count=
wc -l hostlist
total=1
for i in grep -v "^#" hostlist
do
echo "Doing $total or $count $i"
sudo scp -q access.sh $i:/tmp
sudo ssh -q $i /tmp/access.sh
sleep 1
total=expr $total + 1
done
Red Cricket
(2233 rep)
Jul 7, 2016, 05:21 PM
• Last activity: May 12, 2022, 09:55 PM
20
votes
2
answers
93388
views
How do I list all background processes?
Is it possible to list all running background processes with the `ps` command, or is the only option for getting a list of background processes the `jobs` command?
Is it possible to list all running background processes with the
ps
command, or is the only option for getting a list of background processes the jobs
command?
hal
(315 rep)
May 9, 2022, 02:46 PM
• Last activity: May 9, 2022, 03:54 PM
9
votes
4
answers
20890
views
How can I kill a job that was initiated in another shell (terminal window or tab)?
If I begin a process and background it in a terminal window (say `ping google.com &`), I can kill it using `kill %1` (assuming it is job 1). However if I open another terminal window (or tab) the backgrounded process is not listed under `jobs` and cannot be killed directly using `kill`. **Is it poss...
If I begin a process and background it in a terminal window (say
ping google.com &
), I can kill it using kill %1
(assuming it is job 1).
However if I open another terminal window (or tab) the backgrounded process is not listed under jobs
and cannot be killed directly using kill
.
**Is it possible to kill this process from another terminal window or tab?**
Note: I am using the Xfce Terminal Emulator 0.4.3 and bash (although if a solution exists in another common shell but not bash I am open to that as well)
DQdlM
(1553 rep)
Dec 11, 2012, 01:18 AM
• Last activity: Apr 20, 2022, 09:31 AM
9
votes
3
answers
5095
views
process command and the percent sign usage
I am confused about stopping a job by using the percent sign with the kill command. I cannot find any documentation in the man pages for kill that indicate the percent sign can be used. Can someone explain to me if this explanation is hidden somewhere else, or why the `%` sign is used? `kill -s 19 %...
I am confused about stopping a job by using the percent sign with the kill command. I cannot find any documentation in the man pages for kill that indicate the percent sign can be used. Can someone explain to me if this explanation is hidden somewhere else, or why the
%
sign is used?
kill -s 19 %1
would stop the job with an id of 1
Oscalation
(1179 rep)
Mar 12, 2016, 03:56 AM
• Last activity: Apr 16, 2022, 04:10 PM
Showing page 1 of 20 total questions