Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Apr 2012 16:47:57 -0400
From:      Matthew Story <matthewstory@gmail.com>
To:        "illoai@gmail.com" <illoai@gmail.com>
Cc:        questions@freebsd.org
Subject:   Re: current pids per tty
Message-ID:  <CAB%2B9ogd011VRreE5pU5vVCqnvw=Ws-TGet_x9pr7fQF4keBRyQ@mail.gmail.com>
In-Reply-To: <CAHHBGkqw865mGPS-9PSBfFa9qOJO8wJcrsTvfr4aoxw%2B0EF9Eg@mail.gmail.com>
References:  <CAPkyVLzPuX3jxRRRVsJEtcYE%2B4kAaas50RuzbVByEUixuHhQdA@mail.gmail.com> <CAHHBGkqw865mGPS-9PSBfFa9qOJO8wJcrsTvfr4aoxw%2B0EF9Eg@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Apr 3, 2012 at 12:33 PM, illoai@gmail.com <illoai@gmail.com> wrote:

> On 3 April 2012 04:19, takCoder <tak.official@gmail.com> wrote:
> > Hi Everyone,
> >
> > i'm trying to find out a way to list *all* the pids of which running in
> the
> > background of or as the parent *of the current tty* device my shell file
> is
> > running on.. is there a quick way to find it out as for commands like tty
> > (for current tty) or whoami (for current user) or i should just grep and
> > sed the output of commands like w  or ...?
> >
> > as you may know, W(1)'s output just shows the number of pts devices in
> its
> > tty column.. so it won't be that easy to grep them all(i'm somehow new in
> > shell scripting as well).. and i need the detailed info about related
> > processes; like FROM or WHAT outputs of w command.. (BTW, i'm trying to
> > write a reporting per-tty shell script for my FreeBSD system..)
> >
> > it would be very kind of you giving me any tips or tricks on this.
>
> tcsh & sh both have a builtin called "jobs" (there is an executable
> named /usr/bin/jobs, but . . . well run "cat /usr/bin/jobs" & see for
> yourself).  I dunno if that encompasses everything you want to do.
>

Across all TTYs, something like this would probably work:

sudo fstat | awk '$5 ~ /^\/dev/ && $8 ~ /tty/ { printf "%s %s %s\n", $1,
$8, $3; }' | sort -k1,2

from there, if you think you need to trace the process trees down, you can
use this list of pids and ps to do the rest ...

hopefully that helps



>
> --
> --
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "
> freebsd-questions-unsubscribe@freebsd.org"
>



-- 
regards,
matt



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAB%2B9ogd011VRreE5pU5vVCqnvw=Ws-TGet_x9pr7fQF4keBRyQ>