2024-04-12 10:19:32 +00:00
|
|
|
#RUN: %fish %s
|
2020-07-14 12:34:47 +00:00
|
|
|
|
|
|
|
# Verify zombies are not left by disown (#7183, #5342)
|
|
|
|
# Do this first to avoid colliding with the other disowned processes below, which may
|
|
|
|
# still be running at the end of the script
|
|
|
|
sleep 0.2 &
|
|
|
|
disown
|
|
|
|
sleep 0.2
|
|
|
|
echo Trigger process reaping
|
2020-08-08 11:22:24 +00:00
|
|
|
sleep 0.1
|
2020-07-14 12:34:47 +00:00
|
|
|
#CHECK: Trigger process reaping
|
|
|
|
# The initial approach here was to kill the PID of the sleep process, which should
|
|
|
|
# be gone by the time we get here. Unfortunately, kill from procps on pre-2016 distributions
|
2021-03-23 07:14:20 +00:00
|
|
|
# does not print an error for non-existent PIDs, so instead look for zombies in this session.
|
|
|
|
# There could already be zombies from previous tests run in this session or a test could be run
|
|
|
|
# simultaneously that causes a zombie to spawn, so limit the output only to processes started by
|
|
|
|
# this fish instance.
|
2021-06-24 16:19:28 +00:00
|
|
|
if not contains (uname) SunOS
|
2021-03-23 07:14:20 +00:00
|
|
|
ps -o ppid,stat
|
2021-06-24 16:19:28 +00:00
|
|
|
else
|
2021-03-23 07:14:20 +00:00
|
|
|
ps -o ppid,s
|
2021-08-29 18:10:25 +00:00
|
|
|
end | string match -e $fish_pid | string match '*Z*'
|
2020-07-14 12:34:47 +00:00
|
|
|
|
2021-05-20 18:25:32 +00:00
|
|
|
# Verify disown can be used with last_pid, even if it is separate from the pgroup.
|
|
|
|
# This should silently succeed.
|
|
|
|
command true | sleep 0.5 &
|
|
|
|
disown $last_pid
|
|
|
|
|
2020-03-09 18:36:12 +00:00
|
|
|
jobs -q
|
|
|
|
echo $status
|
2020-02-08 08:44:39 +00:00
|
|
|
#CHECK: 1
|
2017-04-02 15:02:55 +00:00
|
|
|
sleep 5 &
|
|
|
|
sleep 5 &
|
2016-06-08 23:09:29 +00:00
|
|
|
jobs -c
|
2020-02-08 08:44:39 +00:00
|
|
|
#CHECK: Command
|
|
|
|
#CHECK: sleep
|
|
|
|
#CHECK: sleep
|
2020-03-09 18:36:12 +00:00
|
|
|
jobs -q
|
|
|
|
echo $status
|
2020-02-08 08:44:39 +00:00
|
|
|
#CHECK: 0
|
2018-04-01 20:43:05 +00:00
|
|
|
bg -23 1 2>/dev/null
|
2017-06-15 01:25:51 +00:00
|
|
|
or echo bg: invalid option -23 >&2
|
2020-02-08 08:44:39 +00:00
|
|
|
#CHECKERR: bg: invalid option -23
|
2016-07-06 06:12:28 +00:00
|
|
|
fg 3
|
2020-02-08 08:44:39 +00:00
|
|
|
#CHECKERR: fg: No suitable job: 3
|
2017-04-02 15:02:55 +00:00
|
|
|
bg 3
|
2020-02-08 08:44:39 +00:00
|
|
|
#CHECKERR: bg: Could not find job '3'
|
2017-03-23 00:50:57 +00:00
|
|
|
sleep 1 &
|
|
|
|
disown
|
|
|
|
jobs -c
|
2020-02-08 08:44:39 +00:00
|
|
|
#CHECK: Command
|
|
|
|
#CHECK: sleep
|
|
|
|
#CHECK: sleep
|
2020-03-26 06:00:31 +00:00
|
|
|
jobs 1
|
|
|
|
echo $status
|
|
|
|
#CHECK: 1
|
|
|
|
#CHECKERR: jobs: No suitable job: 1
|
|
|
|
jobs foo
|
|
|
|
echo $status
|
|
|
|
#CHECK: 2
|
|
|
|
#CHECKERR: jobs: 'foo' is not a valid process id
|
|
|
|
jobs -q 1
|
|
|
|
echo $status
|
|
|
|
#CHECK: 1
|
|
|
|
jobs -q foo
|
|
|
|
echo $status
|
|
|
|
#CHECK: 2
|
|
|
|
#CHECKERR: jobs: 'foo' is not a valid process id
|
2017-03-23 00:50:57 +00:00
|
|
|
disown foo
|
2020-02-08 08:44:39 +00:00
|
|
|
#CHECKERR: disown: 'foo' is not a valid job specifier
|
2017-03-23 00:50:57 +00:00
|
|
|
disown (jobs -p)
|
2016-07-06 06:12:28 +00:00
|
|
|
or exit 0
|
2019-04-19 06:08:16 +00:00
|
|
|
|
2019-04-19 07:20:55 +00:00
|
|
|
# Verify `jobs` output within a function lists background jobs
|
2019-04-19 06:08:16 +00:00
|
|
|
# https://github.com/fish-shell/fish-shell/issues/5824
|
|
|
|
function foo
|
2019-04-19 07:20:55 +00:00
|
|
|
sleep 0.2 &
|
|
|
|
jobs -c
|
2019-04-19 06:08:16 +00:00
|
|
|
end
|
|
|
|
foo
|
2019-05-01 23:17:23 +00:00
|
|
|
|
|
|
|
# Verify we observe job exit events
|
|
|
|
sleep 1 &
|
|
|
|
set sleep_job $last_pid
|
|
|
|
function sleep_done_$sleep_job --on-job-exit $sleep_job
|
|
|
|
/bin/echo "sleep is done"
|
|
|
|
functions --erase sleep_done_$sleep_job
|
|
|
|
end
|
|
|
|
sleep 2
|
2019-09-11 05:17:23 +00:00
|
|
|
|
|
|
|
# Verify `jobs -l` works and returns the right status codes
|
|
|
|
# https://github.com/fish-shell/fish-shell/issues/6104
|
2020-03-09 18:36:12 +00:00
|
|
|
jobs --last --command
|
|
|
|
echo $status
|
2020-02-08 08:44:39 +00:00
|
|
|
#CHECK: Command
|
|
|
|
#CHECK: sleep
|
|
|
|
#CHECK: sleep is done
|
|
|
|
#CHECK: 1
|
2019-09-11 05:17:23 +00:00
|
|
|
sleep 0.2 &
|
2020-03-09 18:36:12 +00:00
|
|
|
jobs -lc
|
|
|
|
echo $status
|
2020-02-08 08:44:39 +00:00
|
|
|
#CHECK: Command
|
|
|
|
#CHECK: sleep
|
|
|
|
#CHECK: 0
|
2021-03-07 09:22:35 +00:00
|
|
|
|
|
|
|
function foo
|
|
|
|
function caller --on-job-exit caller
|
|
|
|
echo caller
|
|
|
|
end
|
|
|
|
echo foo
|
|
|
|
end
|
|
|
|
|
|
|
|
function bar --on-event bar
|
|
|
|
echo (foo)
|
|
|
|
end
|
|
|
|
|
|
|
|
emit bar
|
|
|
|
#CHECK: foo
|
|
|
|
#CHECK: caller
|
2021-02-23 08:09:26 +00:00
|
|
|
|
|
|
|
# We can't rely on a *specific* pgid being assigned,
|
|
|
|
# but we can rely on it not being fish's.
|
|
|
|
command true &
|
|
|
|
set -l truepid $last_pid
|
|
|
|
test $truepid != $fish_pid || echo true has same pid as fish
|
2021-10-28 17:02:48 +00:00
|
|
|
|
|
|
|
# Job exit events work even after the job has exited!
|
|
|
|
sleep .5
|
|
|
|
function thud --on-job-exit $truepid
|
|
|
|
echo "thud called"
|
|
|
|
end
|
|
|
|
# CHECK: thud called
|
2023-11-29 15:57:01 +00:00
|
|
|
|
|
|
|
disown 252
|
|
|
|
# CHECKERR: disown: Could not find job '252'
|