Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When surveying the output of jobs in bash, you'll often get a list like the following:

[root@csx-tzg-sac-01 ~]# jobs
[2]   Running                 ( sleep 600 && ls -lh ~ossadmin/*.iso ) &
[3]-  Running                 ( sleep 900 && ls -lh ~ossadmin/*.iso ) &
[4]+  Running                 ( sleep 900 && ls -lh ~ossadmin/*.iso ) &

Can you determine when a given job was started by the jobid (ie, not by looking at the pid from a place like ps)?

If so, how?

share|improve this question
up vote 2 down vote accepted

You can get the pid of the job from jobs -l, so that you don't have to hunt through ps output to find the job. Is that why you were trying to avoid ps?

jobs -l | sed 's/^\[[0-9]*\][^0-9]*\([0-9][0-9]*\)[^0-9].*/\1/' | xargs ps up

will work in bash and zsh.

If you're using zsh, then the zsh/parameters module provides the $jobstates array variable. Eg:

% echo $jobstates[1]

That can be easier to parse the pid from. And if you're on a system with /proc then the timestamp on the proc dir will tell you when the process was started.

$ ls -ld /proc/$$
share|improve this answer
Bash has jobs -p %1 to print the PID. – grawity Aug 17 '11 at 0:02
yes, I am trying to avoid ps because I may or may not be able to tie the pid to a start time (maybe there's a half dozen commands run that are otherwise identical but separated by seconds or minutes - picking which is which can be difficult/impossible) – warren Aug 17 '11 at 0:05
Right, so my solution works for you: get the pid from jobs, then request the ps details for that one particular pid; you're no longer hunting for the process by name, just looking it up. – Phil P Aug 24 '11 at 7:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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