Cory Petkovsek wrote:

> Doing a google search on wchan only brings up man pages for ps (which I
> have on my system) or for the wchan command (which I don't have, but
> don't think I need).
> 
> On Linux, the kernel gives me the english wchan value for a process:
> select, poll, wait4, unix_stream_data_wait, read_chan, rt_sigsuspend,
> nanosleep, etc.
> 
> Where can I learn more about these values and what they mean?

Get a kernel internals book.  The Lyons book describes these well,
though it covers a very old version of the Unix kernel.  Absent a
kernel book, get the kernel source. (-:

My recollection of wait channels is from Unix, and Linux may not be
exactly the same, though it's close, so read with a grain of salt:

A wait channel is an arbitrary integer that a kernel thread specifies
when it goes to sleep.  Typically, it's the address of a kernel
data structure.  When some other thread or interrupt service
routine decides that something significant has happened (e.g., timer
goes off, I/O completes, the buffer is full/empty), it wakes up the
wait channel, and all the threads waiting on that channel wake up.

For example, let's say a process tries to read from stdin, and stdin
is a pseudo terminal, and there are no characters in the input buffer.
The process has to sleep until input is available, and its wait
channel will be the address of the struct tty for that pseudo
terminal.  Traditionally, the code looked like this (but the API is
much uglier now).

        struct tty *pty = ...;
        ...
        sleep((wchan_t) pty);   /* pty is the wait channel */

Sometime later, a different process, e.g., sshd or xterm, writes
characters to the master side of the pseudo tty.  The code
implementing write(), inside the kernel, will notice that the character
buffer had been empty and is now nonempty, so it will wake up the
channel.  The traditional code looked like this.

        wakeup((wchan_t) pty);

The waker upper doesn't know or care exactly how many sleepers there
are or whether anyone is sleeping at all.  It just knows that a
condition that someone might want to wake up for has happened, so it
wakes up everybody who might be sleeping.

Anyway, sleep() records the wait channel in the sleeper's struct
thread, and ps finds it there and prints it.  (ps uses /proc in Linux;
I don't know the details.)

On my workstation right now, ps reports most processes' wchan as
either do_sel[ect], do_pol[l], nanosl[eep], read_c[har], wait4, or
rt_sig[nal].

do_select, do_poll, wait4, and nanosleep mean the process is blocked
in the select(), poll(), wait4(), and nanosleep() system calls.
read_char means it's blocked reading from a character device (these
are getty processes).  I'm not sure about rt_sig -- I suspect those
processes are blocked in sigpause() or sigsuspend().

Is that what you're asking?

-- 
Bob Miller                              K<bob>
kbobsoft software consulting
http://kbobsoft.com                     [EMAIL PROTECTED]
_______________________________________________
EuG-LUG mailing list
[EMAIL PROTECTED]
http://mailman.efn.org/cgi-bin/listinfo/eug-lug

Reply via email to