Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: fg jobs info
- X-seq: zsh-users 11817
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: fg jobs info
- Date: Wed, 05 Sep 2007 08:30:00 -0700
- In-reply-to: <200709050928.l859Su9h016042@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20070902154306.35880.qmail@xxxxxxxxxxx> <070902105953.ZM22915@xxxxxxxxxxxxxxxxxxxxxx> <20070903163147.GA14017@mastermind> <20070904111631.81486.qmail@xxxxxxxxxxx> <070904083104.ZM25598@xxxxxxxxxxxxxxxxxxxxxx> <20070905090302.72429.qmail@xxxxxxxxxxx> <200709050928.l859Su9h016042@xxxxxxxxxxxxxx>
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
do
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)"}
fi
done
}
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