While in FiSH (Friendly Interactive SHell) I can start a process in the background (something &
). However, if I try to retrieve the process id of the process (PID=$!
) I get an error from fish:
fish: Unknown command “PID=$!”. Did you mean “set PID $!”? For information on assigning values to variables, see the
help section on the set command by typing “help set”.
PID=$!: command not found
How can I retrieve the PID of the background process?
From fish version 3, you can use $last_pid
as a replacement for %last
to get the PID of the last background job.
Using process expansion, you could write
set PID %1 # if you know it's the first background job
set PID %something # if you know it's the only "something" running
Note that this feature is removed in fish version 3.
Otherwise, we can use the jobs
command
set PID (jobs -l | awk '{print $2}') # just get the pid
jobs -l | read jobid pid cpu state cmd # get all the things
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With