/proc/PID/stat breakage [PATCH]

Neil Moore (amethyst@maxwell.ml.org)
Sat, 28 Feb 1998 17:29:07 -0500


Is there any particular reasoning behind the bitmappish TASK_*
constants:

#define TASK_RUNNING 0
#define TASK_INTERRUPTIBLE 1
#define TASK_UNINTERRUPTIBLE 2
#define TASK_ZOMBIE 4
#define TASK_STOPPED 8
#define TASK_SWAPPING 16
?

This breaks proc/PID/stat{,us} -- fs/proc/array.c relied on the old
numbering. Now, zombies report as stopped, and stopped or swapping
processes report as `.'.

Also, does anything rely on the representation of invalid values being
'.'? It seems that '?' would make more sense.

Anyway, I have applied the following patch (against a clean 2.1.88),
and everything seems to work fine now. While it doesn't look as neat
as subscripting, it will continue to work, even if someone changes the
constants again.

--- linux/fs/proc/array.c.orig Sat Feb 28 16:20:57 1998
+++ linux/fs/proc/array.c Sat Feb 28 16:23:02 1998
@@ -613,19 +613,29 @@
static inline char * task_state(struct task_struct *p, char *buffer)
{
#define NR_STATES (sizeof(states)/sizeof(const char *))
- unsigned int n = p->state;
- static const char * states[] = {
- "R (running)",
- "S (sleeping)",
- "D (disk sleep)",
- "Z (zombie)",
- "T (stopped)",
- "W (paging)",
- ". Huh?"
- };
+ const char *state;

- if (n >= NR_STATES)
- n = NR_STATES-1;
+ switch(p->state) {
+ case TASK_RUNNING:
+ state = "R (running)";
+ break;
+ case TASK_INTERRUPTIBLE:
+ state = "S (sleeping)";
+ break;
+ case TASK_UNINTERRUPTIBLE:
+ state = "D (disk sleep)";
+ break;
+ case TASK_ZOMBIE:
+ state = "Z (zombie)";
+ break;
+ case TASK_STOPPED:
+ state = "T (stopped)";
+ break;
+ case TASK_SWAPPING:
+ state = "W (paging)";
+ default:
+ state = ". (invalid)";
+ };

buffer += sprintf(buffer,
"State:\t%s\n"
@@ -633,7 +643,7 @@
"PPid:\t%d\n"
"Uid:\t%d\t%d\t%d\t%d\n"
"Gid:\t%d\t%d\t%d\t%d\n",
- states[n],
+ state,
p->pid, p->p_pptr->pid,
p->uid, p->euid, p->suid, p->fsuid,
p->gid, p->egid, p->sgid, p->fsgid);
@@ -769,10 +779,30 @@

if (!tsk)
return 0;
- if (tsk->state < 0 || tsk->state > 5)
+
+ switch(tsk->state) {
+ case TASK_RUNNING:
+ state = 'R';
+ break;
+ case TASK_INTERRUPTIBLE:
+ state = 'S';
+ break;
+ case TASK_UNINTERRUPTIBLE:
+ state = 'D';
+ break;
+ case TASK_ZOMBIE:
+ state = 'Z';
+ break;
+ case TASK_STOPPED:
+ state = 'T';
+ break;
+ case TASK_SWAPPING:
+ state = 'W';
+ break;
+ default:
state = '.';
- else
- state = "RSDZTW"[tsk->state];
+ };
+
vsize = eip = esp = 0;
if (tsk->mm && tsk->mm != &init_mm) {
struct vm_area_struct *vma = tsk->mm->mmap;

-- 
-Neil Moore, amethyst@maxwell.ml.org, http://www.sfloyd.ml.org/~amethyst/

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu