0

I've opened a terminal session and started some processes with &. When I tried closing the terminal window, it warned me that there were still jobs running in the background.

I can see the processes running with ps, but how can I know which ones were started through this session?

2

jobs -l
Lists process IDs of the active jobs

2

If you want to find all the background processes started from the current bash session, you can use the jobs builtin of bash.

From help jobs:

jobs: jobs [-lnprs] [jobspec ...] or jobs -x command [args]
Display status of jobs.

Lists the active jobs.  JOBSPEC restricts output to that job.
Without options, the status of all active jobs is displayed.

On the other hand if you want to find all the processes that were started from this bash session, you can use the $$ variable of bash which will give you the PID of the current bash instance. Then you can parse the output of ps -ef command to find all the processes whose parent process ID (PPID) is $$:

ps -ef | grep -P "^[^ ]+\s+[^ ]+\s+$$\s"
0

Run ps -auxf to see which shells the background processes are children of.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.