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
26 * $FreeBSD: src/release/picobsd/tinyware/aps/main.c,v 1.2 1999/08/28 01:33:52 peter Exp $
27 * $DragonFly: src/release/picobsd/tinyware/aps/Attic/main.c,v 1.2 2003/06/17 04:27:20 dillon Exp $
33 #include <sys/types.h>
37 * Ok, I could extract almost anything from /proc, but I'm too lazy...
38 * I think it will suffice for now.
42 main(int argc, char *argv[])
48 char *tok, *sep=" ", *sep1=",";
49 char *name, *pid, *ppid, *uid, *gid;
50 char *pgid, *sid, *tty, *cred;
55 printf(" PID PPID TTY COMMAND\n");
56 while((e=readdir(d))!=NULL) {
57 /* Skip '.' and '..' */
58 if(e->d_name[0]=='.') continue;
59 /* Skip 'curproc' - it's us */
60 if(e->d_name[0]=='c') continue;
61 sprintf(buf,"/proc/%s/status",e->d_name);
67 ppid=strtok(NULL,sep);
68 pgid=strtok(NULL,sep);
71 tok=strtok(NULL,sep); /* flags */
72 tok=strtok(NULL,sep); /* start */
73 tok=strtok(NULL,sep); /* user time */
74 tok=strtok(NULL,sep); /* system time */
75 tok=strtok(NULL,sep); /* wchan */
76 cred=strtok(NULL,sep); /* credentials */
77 major=strtok(tty,sep1);
78 minor=strtok(NULL,sep1);
79 if(strcmp(minor,"-1")==0) {
82 if(strcmp(major,"-1")==0) {
84 } else if(strcmp(major,"12")==0) {
86 } else if(strcmp(major,"0")==0) {
89 } else if(strcmp(major,"5")==0) {
92 if((strcmp(major,"v")==0) && (strcmp(minor,"255")==0)) {
96 sprintf(con,"%s%s",major,minor);
97 printf("%5s %5s %4s (%s)\n",pid,ppid,con,name);