Fix bitrot.

This commit is contained in:
abial 2000-11-11 16:12:39 +00:00
parent d3bcad85c8
commit 290f2ce990
2 changed files with 44 additions and 28 deletions

View File

@ -1,5 +1,3 @@
1998.07.17
This is a small 'ps' replacement, which uses information available via This is a small 'ps' replacement, which uses information available via
sysctl(3) interface (contrary to the 'aps', which requires you to mount sysctl(3) interface (contrary to the 'aps', which requires you to mount
procfs(5) to be able to get exactly the same info, so I think that 'sps' procfs(5) to be able to get exactly the same info, so I think that 'sps'
@ -8,10 +6,6 @@ is superior solution).
When I have some time, I'll add usual switches and other functions that normal When I have some time, I'll add usual switches and other functions that normal
'ps' has... 'ps' has...
The most serious limitation of 'sps' is that it's unable to retrieve the whole
command line.
<abial@freebsd.org> <abial@freebsd.org>
$FreeBSD$ $FreeBSD$

View File

@ -39,14 +39,17 @@
#include <sys/proc.h> #include <sys/proc.h>
#include <sys/user.h> #include <sys/user.h>
char p_stat[]="?iRSTZ"; char p_stat[]="?iRSTZWM";
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int mib[3],i=0,num,len; int mib[4],i=0, num, len, j, plen;
struct kinfo_proc kp,*t,*u; int sz = sizeof(struct proc) + sizeof(struct eproc);
char buf[20],vty[5],pst[5]; struct proc *p;
struct eproc *ep;
char buf[MAXPATHLEN],vty[5],pst[5], wmesg[10];
char *t;
int ma,mi; int ma,mi;
mib[0]=CTL_KERN; mib[0]=CTL_KERN;
@ -56,18 +59,38 @@ main(int argc, char *argv[])
perror("sysctl sizing"); perror("sysctl sizing");
exit(1); exit(1);
} }
t=(struct kinfo_proc *)malloc(len); t=(char *)malloc(len);
if(sysctl(mib,3,t,&len,NULL,0)) { if(sysctl(mib,3,t,&len,NULL,0)) {
perror("sysctl info"); perror("sysctl info");
exit(1); exit(1);
} }
num=len / sizeof(struct kinfo_proc); mib[2]=KERN_PROC_ARGS;
num = len / sz;
i=0; i=0;
printf("USERNAME PID PPID PRI NICE TTY STAT WCHAN COMMAND\n"); printf("USERNAME PID PPID PRI NICE TTY STAT WCHAN COMMAND\n");
while(i < num) { while(i < num) {
u=(t+num-i-1); p=(struct proc *)(t + (num - i - 1) * sz);
ma=major(u->kp_eproc.e_tdev); ep=(struct eproc *)(t + (num - i - 1) * sz + sizeof(struct proc));
mi=minor(u->kp_eproc.e_tdev); mib[3]=p->p_pid;
plen = MAXPATHLEN;
if(sysctl(mib,4,buf,&plen,NULL,0)) {
perror("sysctl info");
exit(1);
}
if(plen == 0) {
sprintf(buf, "(%s)", p->p_comm);
} else {
for(j=0; j < plen-1; j++) {
if(buf[j] == '\0') buf[j] = ' ';
}
}
if(strcmp(ep->e_wmesg, "") == 0) {
sprintf(wmesg, "-");
} else {
strcpy(wmesg, ep->e_wmesg);
}
ma=major(ep->e_tdev);
mi=minor(ep->e_tdev);
switch(ma) { switch(ma) {
case 255: case 255:
strcpy(vty,"??"); strcpy(vty,"??");
@ -85,20 +108,19 @@ main(int argc, char *argv[])
sprintf(vty,"p%d",mi); sprintf(vty,"p%d",mi);
break; break;
} }
sprintf(pst,"%c",p_stat[u->kp_proc.p_stat]); sprintf(pst,"%c",p_stat[p->p_stat]);
printf("%8s%5d%5d %3d %4d %3s %-4s %-7s (%s)\n", printf("%8s %5u %5u %3d %4d %3s %-4s %-7s %s\n",
u->kp_eproc.e_login, ep->e_login,
u->kp_proc.p_pid, p->p_pid,
u->kp_eproc.e_ppid, ep->e_ppid,
u->kp_proc.p_priority, p->p_priority - 22,
u->kp_proc.p_nice, p->p_nice,
vty, vty,
pst, pst,
u->kp_eproc.e_wmesg, wmesg,
u->kp_proc.p_comm); buf);
i++; i++;
} }
free(t); free((void *)t);
exit(0); exit(0);
} }