Re: patch for CLONE_PID

Albert D. Cahalan (acahalan@cs.uml.edu)
Mon, 27 Oct 1997 01:00:30 -0500 (EST)


> The tid field is a "thread" id for the task entry. This is zero
> by default, and is set if clone() is ever called for the process
> with the CLONE_PID flag. The tids are allocated from the same
> number pool as the process ids, as this makes modification of
> most pid argument taking system calls straight forward.

I've been working on a better /bin/ps with johnsonm of Red Hat.
Your system may be incompatible with other operating systems that
have kernel thread support. It is easy to fix though: every tid
must be unique. That means the tid can't be zero by default.

You can use the ps output from AIX as a hint.

To display information about processes and kernel threads
controlled by the current terminal, enter: ps -lm

F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
240003 A 26 8984 7190 1 60 20 2974 312 pts/1 0:00 -ksh
400 S - - - 1 60 - - - - - -
200005 A 26 9256 8984 15 67 20 18ed 164 pts/1 0:00 ps
0 R - - - 15 67 - - - - - -

To display information about all processes and kernel
threads, enter: ps -emo THREAD

USER PID PPID TID S C PRI SC WCHAN FLAG TTY BND CMD
jane 1716 19292 - A 10 60 1 * 260801 pts/7 - biod
- - - 4863 S 0 60 0 599e9d8 8400 - - -
- - - 5537 R 10 60 1 5999e18 2420 - 3 -
luke 19292 18524 - A 0 60 0 586ad84 200001 pts/7 - -ksh
- - - 7617 S 0 60 0 586ad84 400 - - -
luke 25864 31168 - A 11 65 0 - 200001 pts/7 - -
- - - 8993 R 11 65 0 - 0 - - -

You can see that the ksh shell with PID 19292 has TID 7617.

Unix98 (the Single UNIX Specification v2, see http://www.opengroup.org)
specifies that ps display a "-" for anything that does not make sense.
Although the standard does not specify thread display, you can be sure
that future versions will.

If the future standard says "no TID for the main thread" then it
is easy to hide the TID in user space. It is not so easy to make
a unique TID from user space if it can not be the PID.

If you must put threads right in /proc, please put a '.' in front
of the number. There may be some tool that looks for a process by
name and kills it. If such a tool finds a thread first, then only
the thread gets killed.

The PID directory itself could be a link to the main thread,
for now at least. Eventually it might be better to have the
PID directory carry more complete information.