Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: fg jobs info

On Sep 5, 10:28am, Peter Stephenson wrote:
} > add a variable that automagically returns the text of the 
} > fg'd job.
} That's $jobtexts.

Well ...

$jobtexts returns the text of any/all of the jobs, by job number.

That doesn't solve the problem of knowing which job number is the job
in the foreground.

OTOH, I can't figure out how knowing that could be useful, because
when a job is in the foreground the shell is blocked in zwaitjob(),
so there's no way for it to do anything useful with the job text.

Furthermore $jobtexts never contains the text of the current job
if that job is *started* in the foreground; it only has jobs that
were at some point backgrounded or stopped (at least as far as the
user of the shell is able to tell, see previous point).

What Atom wants is the text of the job that's *about to be* in the
foreground, the instant *before* the shell hands over control of the
TTY and calls zwaitjob(), plus a hook to be able to do something
with that information.

On linux I think a better way to handle this would be to have another
process monitoring the /proc directory.  The foreground job for each
TTY is always the one where the 5th and 8th fields of /proc/<->/stat
are equal, in which case /proc/<->/cmdline gives the job text.  E.g.

  all_fg_jobs() {
    emulate -L zsh
    local -a j
    local x
    for x in /proc/<->/stat
      j=( $(<$x) )
      # $j[7] is 0 for jobs having no TTY
      if (( $j[7] && $j[5] == $j[8] ))
      then print -R ${(ps:\0:)"$(</proc/$j[1]/cmdline)"}

I think you need to be root to map from the "tty number" represented
by $j[7] to an actual tty device name, so you'd need some meta-info to
know where to send the job text.  Probably you could parse that out of
the output of "ps $j[1]".


Messages sorted by: Reverse Date, Date, Thread, Author