2 * Copyright (c) 1998 Andrzej Bialecki
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/types.h>
36 * Ok, I could extract almost anything from /proc, but I'm too lazy...
37 * I think it will suffice for now.
41 main(int argc, char *argv[])
47 char *tok, *sep=" ", *sep1=",";
48 char *name, *pid, *ppid, *uid, *gid;
49 char *pgid, *sid, *tty, *cred;
54 printf(" PID PPID TTY COMMAND\n");
55 while((e=readdir(d))!=NULL) {
56 /* Skip '.' and '..' */
57 if(e->d_name[0]=='.') continue;
58 /* Skip 'curproc' - it's us */
59 if(e->d_name[0]=='c') continue;
60 sprintf(buf,"/proc/%s/status",e->d_name);
66 ppid=strtok(NULL,sep);
67 pgid=strtok(NULL,sep);
70 tok=strtok(NULL,sep); /* flags */
71 tok=strtok(NULL,sep); /* start */
72 tok=strtok(NULL,sep); /* user time */
73 tok=strtok(NULL,sep); /* system time */
74 tok=strtok(NULL,sep); /* wchan */
75 cred=strtok(NULL,sep); /* credentials */
76 major=strtok(tty,sep1);
77 minor=strtok(NULL,sep1);
78 if(strcmp(minor,"-1")==0) {
81 if(strcmp(major,"-1")==0) {
83 } else if(strcmp(major,"12")==0) {
85 } else if(strcmp(major,"0")==0) {
88 } else if(strcmp(major,"5")==0) {
91 if((strcmp(major,"v")==0) && (strcmp(minor,"255")==0)) {
95 sprintf(con,"%s%s",major,minor);
96 printf("%5s %5s %4s (%s)\n",pid,ppid,con,name);