Add /proc/<pid>/status and /proc/<pid>/stat (the latter being mostly
zeroes for the time being). Prompted by: Nathan Boeger <nathan@khmere.com>
This commit is contained in:
parent
ee8f2f372c
commit
886a6f6fca
@ -54,6 +54,7 @@
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
#include <vm/vm_map.h>
|
||||
#include <vm/vm_param.h>
|
||||
#include <vm/vm_object.h>
|
||||
#include <vm/swap_pager.h>
|
||||
@ -65,8 +66,14 @@
|
||||
|
||||
#include <i386/linux/linprocfs/linprocfs.h>
|
||||
|
||||
#define T2J(x) (((x) * 100) / stathz)
|
||||
#define T2S(x) ((x) / stathz)
|
||||
/*
|
||||
* Various conversion macros
|
||||
*/
|
||||
#define T2J(x) (((x) * 100) / (stathz ? stathz : hz)) /* ticks to jiffies */
|
||||
#define T2S(x) ((x) / (stathz ? stathz : hz)) /* ticks to seconds */
|
||||
#define B2K(x) ((x) >> 10) /* bytes to kbytes */
|
||||
#define P2B(x) ((x) << PAGE_SHIFT) /* pages to bytes */
|
||||
#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* pages to kbytes */
|
||||
|
||||
int
|
||||
linprocfs_domeminfo(curp, p, pfs, uio)
|
||||
@ -143,9 +150,9 @@ linprocfs_domeminfo(curp, p, pfs, uio)
|
||||
"SwapFree: %9lu kB\n",
|
||||
memtotal, memused, memfree, memshared, buffers, cached,
|
||||
swaptotal, swapused, swapfree,
|
||||
memtotal >> 10, memfree >> 10,
|
||||
memshared >> 10, buffers >> 10, cached >> 10,
|
||||
swaptotal >> 10, swapfree >> 10);
|
||||
B2K(memtotal), B2K(memfree),
|
||||
B2K(memshared), B2K(buffers), B2K(cached),
|
||||
B2K(swaptotal), B2K(swapfree));
|
||||
|
||||
xlen = ps - psbuf;
|
||||
xlen -= uio->uio_offset;
|
||||
@ -291,3 +298,161 @@ linprocfs_doversion(curp, p, pfs, uio)
|
||||
return (xlen <= 0 ? 0 : uiomove(ps, xlen, uio));
|
||||
}
|
||||
|
||||
int
|
||||
linprocfs_doprocstat(curp, p, pfs, uio)
|
||||
struct proc *curp;
|
||||
struct proc *p;
|
||||
struct pfsnode *pfs;
|
||||
struct uio *uio;
|
||||
{
|
||||
char *ps, psbuf[1024];
|
||||
int xlen;
|
||||
|
||||
ps = psbuf;
|
||||
ps += sprintf(ps, "%d", p->p_pid);
|
||||
#define PS_ADD(name, fmt, arg) ps += sprintf(ps, " " fmt, arg)
|
||||
PS_ADD("comm", "(%s)", p->p_comm);
|
||||
PS_ADD("statr", "%c", '0'); /* XXX */
|
||||
PS_ADD("ppid", "%d", p->p_pptr->p_pid);
|
||||
PS_ADD("pgrp", "%d", p->p_pgid);
|
||||
PS_ADD("session", "%d", p->p_session->s_sid);
|
||||
PS_ADD("tty", "%d", 0); /* XXX */
|
||||
PS_ADD("tpgid", "%d", 0); /* XXX */
|
||||
PS_ADD("flags", "%u", 0); /* XXX */
|
||||
PS_ADD("minflt", "%u", 0); /* XXX */
|
||||
PS_ADD("cminflt", "%u", 0); /* XXX */
|
||||
PS_ADD("majflt", "%u", 0); /* XXX */
|
||||
PS_ADD("cminflt", "%u", 0); /* XXX */
|
||||
PS_ADD("utime", "%d", 0); /* XXX */
|
||||
PS_ADD("stime", "%d", 0); /* XXX */
|
||||
PS_ADD("cutime", "%d", 0); /* XXX */
|
||||
PS_ADD("cstime", "%d", 0); /* XXX */
|
||||
PS_ADD("counter", "%d", 0); /* XXX */
|
||||
PS_ADD("priority", "%d", 0); /* XXX */
|
||||
PS_ADD("timeout", "%u", 0); /* XXX */
|
||||
PS_ADD("itrealvalue", "%u", 0); /* XXX */
|
||||
PS_ADD("starttime", "%d", 0); /* XXX */
|
||||
PS_ADD("vsize", "%u", 0); /* XXX */
|
||||
PS_ADD("rss", "%u", 0); /* XXX */
|
||||
PS_ADD("rlim", "%u", 0); /* XXX */
|
||||
PS_ADD("startcode", "%u", 0); /* XXX */
|
||||
PS_ADD("endcode", "%u", 0); /* XXX */
|
||||
PS_ADD("startstack", "%u", 0); /* XXX */
|
||||
PS_ADD("kstkesp", "%u", 0); /* XXX */
|
||||
PS_ADD("kstkeip", "%u", 0); /* XXX */
|
||||
PS_ADD("signal", "%d", 0); /* XXX */
|
||||
PS_ADD("blocked", "%d", 0); /* XXX */
|
||||
PS_ADD("sigignore", "%d", 0); /* XXX */
|
||||
PS_ADD("sigcatch", "%d", 0); /* XXX */
|
||||
PS_ADD("wchan", "%u", 0); /* XXX */
|
||||
#undef PS_ADD
|
||||
ps += sprintf(ps, "\n");
|
||||
|
||||
xlen = ps - psbuf;
|
||||
xlen -= uio->uio_offset;
|
||||
ps = psbuf + uio->uio_offset;
|
||||
xlen = imin(xlen, uio->uio_resid);
|
||||
return (xlen <= 0 ? 0 : uiomove(ps, xlen, uio));
|
||||
}
|
||||
|
||||
/*
|
||||
* Map process state to descriptive letter. Note that this does not
|
||||
* quite correspond to what Linux outputs, but it's close enough.
|
||||
*/
|
||||
static char *state_str[] = {
|
||||
"? (unknown)",
|
||||
"I (idle)",
|
||||
"R (running)",
|
||||
"S (sleeping)",
|
||||
"T (stopped)",
|
||||
"Z (zombie)",
|
||||
"W (waiting)",
|
||||
"M (mutex)"
|
||||
};
|
||||
|
||||
int
|
||||
linprocfs_doprocstatus(curp, p, pfs, uio)
|
||||
struct proc *curp;
|
||||
struct proc *p;
|
||||
struct pfsnode *pfs;
|
||||
struct uio *uio;
|
||||
{
|
||||
char *ps, psbuf[1024];
|
||||
char *state;
|
||||
int i, xlen;
|
||||
|
||||
ps = psbuf;
|
||||
|
||||
if (p->p_stat > sizeof state_str / sizeof *state_str)
|
||||
state = state_str[0];
|
||||
else
|
||||
state = state_str[(int)p->p_stat];
|
||||
|
||||
#define PS_ADD ps += sprintf
|
||||
PS_ADD(ps, "Name:\t%s\n", p->p_comm); /* XXX escape */
|
||||
PS_ADD(ps, "State:\t%s\n", state);
|
||||
|
||||
/*
|
||||
* Credentials
|
||||
*/
|
||||
PS_ADD(ps, "Pid:\t%d\n", p->p_pid);
|
||||
PS_ADD(ps, "PPid:\t%d\n", p->p_pptr->p_pid);
|
||||
PS_ADD(ps, "Uid:\t%d %d %d %d\n", p->p_cred->p_ruid,
|
||||
p->p_ucred->cr_uid,
|
||||
p->p_cred->p_svuid,
|
||||
/* FreeBSD doesn't have fsuid */
|
||||
p->p_ucred->cr_uid);
|
||||
PS_ADD(ps, "Gid:\t%d %d %d %d\n", p->p_cred->p_rgid,
|
||||
p->p_ucred->cr_gid,
|
||||
p->p_cred->p_svgid,
|
||||
/* FreeBSD doesn't have fsgid */
|
||||
p->p_ucred->cr_gid);
|
||||
PS_ADD(ps, "Groups:\t");
|
||||
for (i = 0; i < p->p_ucred->cr_ngroups; i++)
|
||||
PS_ADD(ps, "%d ", p->p_ucred->cr_groups[i]);
|
||||
PS_ADD(ps, "\n");
|
||||
|
||||
/*
|
||||
* Memory
|
||||
*/
|
||||
PS_ADD(ps, "VmSize:\t%8u kB\n", B2K(p->p_vmspace->vm_map.size));
|
||||
PS_ADD(ps, "VmLck:\t%8u kB\n", P2K(0)); /* XXX */
|
||||
/* XXX vm_rssize seems to always be zero, how can this be? */
|
||||
PS_ADD(ps, "VmRss:\t%8u kB\n", P2K(p->p_vmspace->vm_rssize));
|
||||
PS_ADD(ps, "VmData:\t%8u kB\n", P2K(p->p_vmspace->vm_dsize));
|
||||
PS_ADD(ps, "VmStk:\t%8u kB\n", P2K(p->p_vmspace->vm_ssize));
|
||||
PS_ADD(ps, "VmExe:\t%8u kB\n", P2K(p->p_vmspace->vm_tsize));
|
||||
PS_ADD(ps, "VmLib:\t%8u kB\n", P2K(0)); /* XXX */
|
||||
|
||||
/*
|
||||
* Signal masks
|
||||
*
|
||||
* We support up to 128 signals, while Linux supports 32,
|
||||
* but we only define 32 (the same 32 as Linux, to boot), so
|
||||
* just show the lower 32 bits of each mask. XXX hack.
|
||||
*
|
||||
* NB: on certain platforms (Sparc at least) Linux actually
|
||||
* supports 64 signals, but this code is a long way from
|
||||
* running on anything but i386, so ignore that for now.
|
||||
*/
|
||||
PS_ADD(ps, "SigPnd:\t%08x\n", p->p_siglist.__bits[0]);
|
||||
PS_ADD(ps, "SigBlk:\t%08x\n", 0); /* XXX */
|
||||
PS_ADD(ps, "SigIgn:\t%08x\n", p->p_sigignore.__bits[0]);
|
||||
PS_ADD(ps, "SigCgt:\t%08x\n", p->p_sigcatch.__bits[0]);
|
||||
|
||||
/*
|
||||
* Linux also prints the capability masks, but we don't have
|
||||
* capabilities yet, and when we do get them they're likely to
|
||||
* be meaningless to Linux programs, so we lie. XXX
|
||||
*/
|
||||
PS_ADD(ps, "CapInh:\t%016x\n", 0);
|
||||
PS_ADD(ps, "CapPrm:\t%016x\n", 0);
|
||||
PS_ADD(ps, "CapEff:\t%016x\n", 0);
|
||||
#undef PS_ADD
|
||||
|
||||
xlen = ps - psbuf;
|
||||
xlen -= uio->uio_offset;
|
||||
ps = psbuf + uio->uio_offset;
|
||||
xlen = imin(xlen, uio->uio_resid);
|
||||
return (xlen <= 0 ? 0 : uiomove(ps, xlen, uio));
|
||||
}
|
||||
|
@ -50,6 +50,8 @@ typedef enum {
|
||||
Pproc, /* a process-specific sub-directory */
|
||||
Pexe, /* the executable file */
|
||||
Pmem, /* the process's memory image */
|
||||
Pprocstat, /* the process's status */
|
||||
Pprocstatus, /* the process's status (again) */
|
||||
Pmeminfo, /* memory system statistics */
|
||||
Pcpuinfo, /* CPU model, speed and features */
|
||||
Pstat, /* kernel/system statistics */
|
||||
@ -128,6 +130,8 @@ int linprocfs_docpuinfo __P((struct proc *, struct proc *, struct pfsnode *pfsp,
|
||||
int linprocfs_dostat __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int linprocfs_douptime __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int linprocfs_doversion __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int linprocfs_doprocstat __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int linprocfs_doprocstatus __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
|
||||
/* functions to check whether or not files should be displayed */
|
||||
int linprocfs_validfile __P((struct proc *));
|
||||
|
@ -54,6 +54,7 @@
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
#include <vm/vm_map.h>
|
||||
#include <vm/vm_param.h>
|
||||
#include <vm/vm_object.h>
|
||||
#include <vm/swap_pager.h>
|
||||
@ -65,8 +66,14 @@
|
||||
|
||||
#include <i386/linux/linprocfs/linprocfs.h>
|
||||
|
||||
#define T2J(x) (((x) * 100) / stathz)
|
||||
#define T2S(x) ((x) / stathz)
|
||||
/*
|
||||
* Various conversion macros
|
||||
*/
|
||||
#define T2J(x) (((x) * 100) / (stathz ? stathz : hz)) /* ticks to jiffies */
|
||||
#define T2S(x) ((x) / (stathz ? stathz : hz)) /* ticks to seconds */
|
||||
#define B2K(x) ((x) >> 10) /* bytes to kbytes */
|
||||
#define P2B(x) ((x) << PAGE_SHIFT) /* pages to bytes */
|
||||
#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* pages to kbytes */
|
||||
|
||||
int
|
||||
linprocfs_domeminfo(curp, p, pfs, uio)
|
||||
@ -143,9 +150,9 @@ linprocfs_domeminfo(curp, p, pfs, uio)
|
||||
"SwapFree: %9lu kB\n",
|
||||
memtotal, memused, memfree, memshared, buffers, cached,
|
||||
swaptotal, swapused, swapfree,
|
||||
memtotal >> 10, memfree >> 10,
|
||||
memshared >> 10, buffers >> 10, cached >> 10,
|
||||
swaptotal >> 10, swapfree >> 10);
|
||||
B2K(memtotal), B2K(memfree),
|
||||
B2K(memshared), B2K(buffers), B2K(cached),
|
||||
B2K(swaptotal), B2K(swapfree));
|
||||
|
||||
xlen = ps - psbuf;
|
||||
xlen -= uio->uio_offset;
|
||||
@ -291,3 +298,161 @@ linprocfs_doversion(curp, p, pfs, uio)
|
||||
return (xlen <= 0 ? 0 : uiomove(ps, xlen, uio));
|
||||
}
|
||||
|
||||
int
|
||||
linprocfs_doprocstat(curp, p, pfs, uio)
|
||||
struct proc *curp;
|
||||
struct proc *p;
|
||||
struct pfsnode *pfs;
|
||||
struct uio *uio;
|
||||
{
|
||||
char *ps, psbuf[1024];
|
||||
int xlen;
|
||||
|
||||
ps = psbuf;
|
||||
ps += sprintf(ps, "%d", p->p_pid);
|
||||
#define PS_ADD(name, fmt, arg) ps += sprintf(ps, " " fmt, arg)
|
||||
PS_ADD("comm", "(%s)", p->p_comm);
|
||||
PS_ADD("statr", "%c", '0'); /* XXX */
|
||||
PS_ADD("ppid", "%d", p->p_pptr->p_pid);
|
||||
PS_ADD("pgrp", "%d", p->p_pgid);
|
||||
PS_ADD("session", "%d", p->p_session->s_sid);
|
||||
PS_ADD("tty", "%d", 0); /* XXX */
|
||||
PS_ADD("tpgid", "%d", 0); /* XXX */
|
||||
PS_ADD("flags", "%u", 0); /* XXX */
|
||||
PS_ADD("minflt", "%u", 0); /* XXX */
|
||||
PS_ADD("cminflt", "%u", 0); /* XXX */
|
||||
PS_ADD("majflt", "%u", 0); /* XXX */
|
||||
PS_ADD("cminflt", "%u", 0); /* XXX */
|
||||
PS_ADD("utime", "%d", 0); /* XXX */
|
||||
PS_ADD("stime", "%d", 0); /* XXX */
|
||||
PS_ADD("cutime", "%d", 0); /* XXX */
|
||||
PS_ADD("cstime", "%d", 0); /* XXX */
|
||||
PS_ADD("counter", "%d", 0); /* XXX */
|
||||
PS_ADD("priority", "%d", 0); /* XXX */
|
||||
PS_ADD("timeout", "%u", 0); /* XXX */
|
||||
PS_ADD("itrealvalue", "%u", 0); /* XXX */
|
||||
PS_ADD("starttime", "%d", 0); /* XXX */
|
||||
PS_ADD("vsize", "%u", 0); /* XXX */
|
||||
PS_ADD("rss", "%u", 0); /* XXX */
|
||||
PS_ADD("rlim", "%u", 0); /* XXX */
|
||||
PS_ADD("startcode", "%u", 0); /* XXX */
|
||||
PS_ADD("endcode", "%u", 0); /* XXX */
|
||||
PS_ADD("startstack", "%u", 0); /* XXX */
|
||||
PS_ADD("kstkesp", "%u", 0); /* XXX */
|
||||
PS_ADD("kstkeip", "%u", 0); /* XXX */
|
||||
PS_ADD("signal", "%d", 0); /* XXX */
|
||||
PS_ADD("blocked", "%d", 0); /* XXX */
|
||||
PS_ADD("sigignore", "%d", 0); /* XXX */
|
||||
PS_ADD("sigcatch", "%d", 0); /* XXX */
|
||||
PS_ADD("wchan", "%u", 0); /* XXX */
|
||||
#undef PS_ADD
|
||||
ps += sprintf(ps, "\n");
|
||||
|
||||
xlen = ps - psbuf;
|
||||
xlen -= uio->uio_offset;
|
||||
ps = psbuf + uio->uio_offset;
|
||||
xlen = imin(xlen, uio->uio_resid);
|
||||
return (xlen <= 0 ? 0 : uiomove(ps, xlen, uio));
|
||||
}
|
||||
|
||||
/*
|
||||
* Map process state to descriptive letter. Note that this does not
|
||||
* quite correspond to what Linux outputs, but it's close enough.
|
||||
*/
|
||||
static char *state_str[] = {
|
||||
"? (unknown)",
|
||||
"I (idle)",
|
||||
"R (running)",
|
||||
"S (sleeping)",
|
||||
"T (stopped)",
|
||||
"Z (zombie)",
|
||||
"W (waiting)",
|
||||
"M (mutex)"
|
||||
};
|
||||
|
||||
int
|
||||
linprocfs_doprocstatus(curp, p, pfs, uio)
|
||||
struct proc *curp;
|
||||
struct proc *p;
|
||||
struct pfsnode *pfs;
|
||||
struct uio *uio;
|
||||
{
|
||||
char *ps, psbuf[1024];
|
||||
char *state;
|
||||
int i, xlen;
|
||||
|
||||
ps = psbuf;
|
||||
|
||||
if (p->p_stat > sizeof state_str / sizeof *state_str)
|
||||
state = state_str[0];
|
||||
else
|
||||
state = state_str[(int)p->p_stat];
|
||||
|
||||
#define PS_ADD ps += sprintf
|
||||
PS_ADD(ps, "Name:\t%s\n", p->p_comm); /* XXX escape */
|
||||
PS_ADD(ps, "State:\t%s\n", state);
|
||||
|
||||
/*
|
||||
* Credentials
|
||||
*/
|
||||
PS_ADD(ps, "Pid:\t%d\n", p->p_pid);
|
||||
PS_ADD(ps, "PPid:\t%d\n", p->p_pptr->p_pid);
|
||||
PS_ADD(ps, "Uid:\t%d %d %d %d\n", p->p_cred->p_ruid,
|
||||
p->p_ucred->cr_uid,
|
||||
p->p_cred->p_svuid,
|
||||
/* FreeBSD doesn't have fsuid */
|
||||
p->p_ucred->cr_uid);
|
||||
PS_ADD(ps, "Gid:\t%d %d %d %d\n", p->p_cred->p_rgid,
|
||||
p->p_ucred->cr_gid,
|
||||
p->p_cred->p_svgid,
|
||||
/* FreeBSD doesn't have fsgid */
|
||||
p->p_ucred->cr_gid);
|
||||
PS_ADD(ps, "Groups:\t");
|
||||
for (i = 0; i < p->p_ucred->cr_ngroups; i++)
|
||||
PS_ADD(ps, "%d ", p->p_ucred->cr_groups[i]);
|
||||
PS_ADD(ps, "\n");
|
||||
|
||||
/*
|
||||
* Memory
|
||||
*/
|
||||
PS_ADD(ps, "VmSize:\t%8u kB\n", B2K(p->p_vmspace->vm_map.size));
|
||||
PS_ADD(ps, "VmLck:\t%8u kB\n", P2K(0)); /* XXX */
|
||||
/* XXX vm_rssize seems to always be zero, how can this be? */
|
||||
PS_ADD(ps, "VmRss:\t%8u kB\n", P2K(p->p_vmspace->vm_rssize));
|
||||
PS_ADD(ps, "VmData:\t%8u kB\n", P2K(p->p_vmspace->vm_dsize));
|
||||
PS_ADD(ps, "VmStk:\t%8u kB\n", P2K(p->p_vmspace->vm_ssize));
|
||||
PS_ADD(ps, "VmExe:\t%8u kB\n", P2K(p->p_vmspace->vm_tsize));
|
||||
PS_ADD(ps, "VmLib:\t%8u kB\n", P2K(0)); /* XXX */
|
||||
|
||||
/*
|
||||
* Signal masks
|
||||
*
|
||||
* We support up to 128 signals, while Linux supports 32,
|
||||
* but we only define 32 (the same 32 as Linux, to boot), so
|
||||
* just show the lower 32 bits of each mask. XXX hack.
|
||||
*
|
||||
* NB: on certain platforms (Sparc at least) Linux actually
|
||||
* supports 64 signals, but this code is a long way from
|
||||
* running on anything but i386, so ignore that for now.
|
||||
*/
|
||||
PS_ADD(ps, "SigPnd:\t%08x\n", p->p_siglist.__bits[0]);
|
||||
PS_ADD(ps, "SigBlk:\t%08x\n", 0); /* XXX */
|
||||
PS_ADD(ps, "SigIgn:\t%08x\n", p->p_sigignore.__bits[0]);
|
||||
PS_ADD(ps, "SigCgt:\t%08x\n", p->p_sigcatch.__bits[0]);
|
||||
|
||||
/*
|
||||
* Linux also prints the capability masks, but we don't have
|
||||
* capabilities yet, and when we do get them they're likely to
|
||||
* be meaningless to Linux programs, so we lie. XXX
|
||||
*/
|
||||
PS_ADD(ps, "CapInh:\t%016x\n", 0);
|
||||
PS_ADD(ps, "CapPrm:\t%016x\n", 0);
|
||||
PS_ADD(ps, "CapEff:\t%016x\n", 0);
|
||||
#undef PS_ADD
|
||||
|
||||
xlen = ps - psbuf;
|
||||
xlen -= uio->uio_offset;
|
||||
ps = psbuf + uio->uio_offset;
|
||||
xlen = imin(xlen, uio->uio_resid);
|
||||
return (xlen <= 0 ? 0 : uiomove(ps, xlen, uio));
|
||||
}
|
||||
|
@ -175,6 +175,10 @@ linprocfs_allocvp(mp, vpp, pid, pfs_type)
|
||||
vp->v_type = VREG;
|
||||
break;
|
||||
|
||||
case Pprocstat:
|
||||
case Pprocstatus:
|
||||
/* fallthrough */
|
||||
|
||||
case Pmeminfo:
|
||||
case Pcpuinfo:
|
||||
case Pstat:
|
||||
@ -251,6 +255,12 @@ linprocfs_rw(ap)
|
||||
case Pmem:
|
||||
rtval = procfs_domem(curp, p, pfs, uio);
|
||||
break;
|
||||
case Pprocstat:
|
||||
rtval = linprocfs_doprocstat(curp, p, pfs, uio);
|
||||
break;
|
||||
case Pprocstatus:
|
||||
rtval = linprocfs_doprocstatus(curp, p, pfs, uio);
|
||||
break;
|
||||
case Pmeminfo:
|
||||
rtval = linprocfs_domeminfo(curp, p, pfs, uio);
|
||||
break;
|
||||
|
@ -99,6 +99,8 @@ static struct proc_target {
|
||||
{ DT_DIR, N(".."), Proot, NULL },
|
||||
{ DT_REG, N("mem"), Pmem, NULL },
|
||||
{ DT_LNK, N("exe"), Pexe, NULL },
|
||||
{ DT_REG, N("stat"), Pprocstat, NULL },
|
||||
{ DT_REG, N("status"), Pprocstatus, NULL },
|
||||
#undef N
|
||||
};
|
||||
static const int nproc_targets = sizeof(proc_targets) / sizeof(proc_targets[0]);
|
||||
@ -547,6 +549,12 @@ linprocfs_getattr(ap)
|
||||
vap->va_gid = KMEM_GROUP;
|
||||
break;
|
||||
|
||||
case Pprocstat:
|
||||
case Pprocstatus:
|
||||
vap->va_bytes = vap->va_size = 0;
|
||||
/* uid, gid are already set */
|
||||
break;
|
||||
|
||||
default:
|
||||
panic("linprocfs_getattr");
|
||||
}
|
||||
@ -609,6 +617,9 @@ linprocfs_access(ap)
|
||||
case Pself:
|
||||
case Pmeminfo:
|
||||
case Pcpuinfo:
|
||||
case Pstat:
|
||||
case Puptime:
|
||||
case Pversion:
|
||||
break;
|
||||
default:
|
||||
procp = PFIND(pfs->pfs_pid);
|
||||
|
@ -50,6 +50,8 @@ typedef enum {
|
||||
Pproc, /* a process-specific sub-directory */
|
||||
Pexe, /* the executable file */
|
||||
Pmem, /* the process's memory image */
|
||||
Pprocstat, /* the process's status */
|
||||
Pprocstatus, /* the process's status (again) */
|
||||
Pmeminfo, /* memory system statistics */
|
||||
Pcpuinfo, /* CPU model, speed and features */
|
||||
Pstat, /* kernel/system statistics */
|
||||
@ -128,6 +130,8 @@ int linprocfs_docpuinfo __P((struct proc *, struct proc *, struct pfsnode *pfsp,
|
||||
int linprocfs_dostat __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int linprocfs_douptime __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int linprocfs_doversion __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int linprocfs_doprocstat __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
int linprocfs_doprocstatus __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
|
||||
|
||||
/* functions to check whether or not files should be displayed */
|
||||
int linprocfs_validfile __P((struct proc *));
|
||||
|
@ -54,6 +54,7 @@
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
#include <vm/vm_map.h>
|
||||
#include <vm/vm_param.h>
|
||||
#include <vm/vm_object.h>
|
||||
#include <vm/swap_pager.h>
|
||||
@ -65,8 +66,14 @@
|
||||
|
||||
#include <i386/linux/linprocfs/linprocfs.h>
|
||||
|
||||
#define T2J(x) (((x) * 100) / stathz)
|
||||
#define T2S(x) ((x) / stathz)
|
||||
/*
|
||||
* Various conversion macros
|
||||
*/
|
||||
#define T2J(x) (((x) * 100) / (stathz ? stathz : hz)) /* ticks to jiffies */
|
||||
#define T2S(x) ((x) / (stathz ? stathz : hz)) /* ticks to seconds */
|
||||
#define B2K(x) ((x) >> 10) /* bytes to kbytes */
|
||||
#define P2B(x) ((x) << PAGE_SHIFT) /* pages to bytes */
|
||||
#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* pages to kbytes */
|
||||
|
||||
int
|
||||
linprocfs_domeminfo(curp, p, pfs, uio)
|
||||
@ -143,9 +150,9 @@ linprocfs_domeminfo(curp, p, pfs, uio)
|
||||
"SwapFree: %9lu kB\n",
|
||||
memtotal, memused, memfree, memshared, buffers, cached,
|
||||
swaptotal, swapused, swapfree,
|
||||
memtotal >> 10, memfree >> 10,
|
||||
memshared >> 10, buffers >> 10, cached >> 10,
|
||||
swaptotal >> 10, swapfree >> 10);
|
||||
B2K(memtotal), B2K(memfree),
|
||||
B2K(memshared), B2K(buffers), B2K(cached),
|
||||
B2K(swaptotal), B2K(swapfree));
|
||||
|
||||
xlen = ps - psbuf;
|
||||
xlen -= uio->uio_offset;
|
||||
@ -291,3 +298,161 @@ linprocfs_doversion(curp, p, pfs, uio)
|
||||
return (xlen <= 0 ? 0 : uiomove(ps, xlen, uio));
|
||||
}
|
||||
|
||||
int
|
||||
linprocfs_doprocstat(curp, p, pfs, uio)
|
||||
struct proc *curp;
|
||||
struct proc *p;
|
||||
struct pfsnode *pfs;
|
||||
struct uio *uio;
|
||||
{
|
||||
char *ps, psbuf[1024];
|
||||
int xlen;
|
||||
|
||||
ps = psbuf;
|
||||
ps += sprintf(ps, "%d", p->p_pid);
|
||||
#define PS_ADD(name, fmt, arg) ps += sprintf(ps, " " fmt, arg)
|
||||
PS_ADD("comm", "(%s)", p->p_comm);
|
||||
PS_ADD("statr", "%c", '0'); /* XXX */
|
||||
PS_ADD("ppid", "%d", p->p_pptr->p_pid);
|
||||
PS_ADD("pgrp", "%d", p->p_pgid);
|
||||
PS_ADD("session", "%d", p->p_session->s_sid);
|
||||
PS_ADD("tty", "%d", 0); /* XXX */
|
||||
PS_ADD("tpgid", "%d", 0); /* XXX */
|
||||
PS_ADD("flags", "%u", 0); /* XXX */
|
||||
PS_ADD("minflt", "%u", 0); /* XXX */
|
||||
PS_ADD("cminflt", "%u", 0); /* XXX */
|
||||
PS_ADD("majflt", "%u", 0); /* XXX */
|
||||
PS_ADD("cminflt", "%u", 0); /* XXX */
|
||||
PS_ADD("utime", "%d", 0); /* XXX */
|
||||
PS_ADD("stime", "%d", 0); /* XXX */
|
||||
PS_ADD("cutime", "%d", 0); /* XXX */
|
||||
PS_ADD("cstime", "%d", 0); /* XXX */
|
||||
PS_ADD("counter", "%d", 0); /* XXX */
|
||||
PS_ADD("priority", "%d", 0); /* XXX */
|
||||
PS_ADD("timeout", "%u", 0); /* XXX */
|
||||
PS_ADD("itrealvalue", "%u", 0); /* XXX */
|
||||
PS_ADD("starttime", "%d", 0); /* XXX */
|
||||
PS_ADD("vsize", "%u", 0); /* XXX */
|
||||
PS_ADD("rss", "%u", 0); /* XXX */
|
||||
PS_ADD("rlim", "%u", 0); /* XXX */
|
||||
PS_ADD("startcode", "%u", 0); /* XXX */
|
||||
PS_ADD("endcode", "%u", 0); /* XXX */
|
||||
PS_ADD("startstack", "%u", 0); /* XXX */
|
||||
PS_ADD("kstkesp", "%u", 0); /* XXX */
|
||||
PS_ADD("kstkeip", "%u", 0); /* XXX */
|
||||
PS_ADD("signal", "%d", 0); /* XXX */
|
||||
PS_ADD("blocked", "%d", 0); /* XXX */
|
||||
PS_ADD("sigignore", "%d", 0); /* XXX */
|
||||
PS_ADD("sigcatch", "%d", 0); /* XXX */
|
||||
PS_ADD("wchan", "%u", 0); /* XXX */
|
||||
#undef PS_ADD
|
||||
ps += sprintf(ps, "\n");
|
||||
|
||||
xlen = ps - psbuf;
|
||||
xlen -= uio->uio_offset;
|
||||
ps = psbuf + uio->uio_offset;
|
||||
xlen = imin(xlen, uio->uio_resid);
|
||||
return (xlen <= 0 ? 0 : uiomove(ps, xlen, uio));
|
||||
}
|
||||
|
||||
/*
|
||||
* Map process state to descriptive letter. Note that this does not
|
||||
* quite correspond to what Linux outputs, but it's close enough.
|
||||
*/
|
||||
static char *state_str[] = {
|
||||
"? (unknown)",
|
||||
"I (idle)",
|
||||
"R (running)",
|
||||
"S (sleeping)",
|
||||
"T (stopped)",
|
||||
"Z (zombie)",
|
||||
"W (waiting)",
|
||||
"M (mutex)"
|
||||
};
|
||||
|
||||
int
|
||||
linprocfs_doprocstatus(curp, p, pfs, uio)
|
||||
struct proc *curp;
|
||||
struct proc *p;
|
||||
struct pfsnode *pfs;
|
||||
struct uio *uio;
|
||||
{
|
||||
char *ps, psbuf[1024];
|
||||
char *state;
|
||||
int i, xlen;
|
||||
|
||||
ps = psbuf;
|
||||
|
||||
if (p->p_stat > sizeof state_str / sizeof *state_str)
|
||||
state = state_str[0];
|
||||
else
|
||||
state = state_str[(int)p->p_stat];
|
||||
|
||||
#define PS_ADD ps += sprintf
|
||||
PS_ADD(ps, "Name:\t%s\n", p->p_comm); /* XXX escape */
|
||||
PS_ADD(ps, "State:\t%s\n", state);
|
||||
|
||||
/*
|
||||
* Credentials
|
||||
*/
|
||||
PS_ADD(ps, "Pid:\t%d\n", p->p_pid);
|
||||
PS_ADD(ps, "PPid:\t%d\n", p->p_pptr->p_pid);
|
||||
PS_ADD(ps, "Uid:\t%d %d %d %d\n", p->p_cred->p_ruid,
|
||||
p->p_ucred->cr_uid,
|
||||
p->p_cred->p_svuid,
|
||||
/* FreeBSD doesn't have fsuid */
|
||||
p->p_ucred->cr_uid);
|
||||
PS_ADD(ps, "Gid:\t%d %d %d %d\n", p->p_cred->p_rgid,
|
||||
p->p_ucred->cr_gid,
|
||||
p->p_cred->p_svgid,
|
||||
/* FreeBSD doesn't have fsgid */
|
||||
p->p_ucred->cr_gid);
|
||||
PS_ADD(ps, "Groups:\t");
|
||||
for (i = 0; i < p->p_ucred->cr_ngroups; i++)
|
||||
PS_ADD(ps, "%d ", p->p_ucred->cr_groups[i]);
|
||||
PS_ADD(ps, "\n");
|
||||
|
||||
/*
|
||||
* Memory
|
||||
*/
|
||||
PS_ADD(ps, "VmSize:\t%8u kB\n", B2K(p->p_vmspace->vm_map.size));
|
||||
PS_ADD(ps, "VmLck:\t%8u kB\n", P2K(0)); /* XXX */
|
||||
/* XXX vm_rssize seems to always be zero, how can this be? */
|
||||
PS_ADD(ps, "VmRss:\t%8u kB\n", P2K(p->p_vmspace->vm_rssize));
|
||||
PS_ADD(ps, "VmData:\t%8u kB\n", P2K(p->p_vmspace->vm_dsize));
|
||||
PS_ADD(ps, "VmStk:\t%8u kB\n", P2K(p->p_vmspace->vm_ssize));
|
||||
PS_ADD(ps, "VmExe:\t%8u kB\n", P2K(p->p_vmspace->vm_tsize));
|
||||
PS_ADD(ps, "VmLib:\t%8u kB\n", P2K(0)); /* XXX */
|
||||
|
||||
/*
|
||||
* Signal masks
|
||||
*
|
||||
* We support up to 128 signals, while Linux supports 32,
|
||||
* but we only define 32 (the same 32 as Linux, to boot), so
|
||||
* just show the lower 32 bits of each mask. XXX hack.
|
||||
*
|
||||
* NB: on certain platforms (Sparc at least) Linux actually
|
||||
* supports 64 signals, but this code is a long way from
|
||||
* running on anything but i386, so ignore that for now.
|
||||
*/
|
||||
PS_ADD(ps, "SigPnd:\t%08x\n", p->p_siglist.__bits[0]);
|
||||
PS_ADD(ps, "SigBlk:\t%08x\n", 0); /* XXX */
|
||||
PS_ADD(ps, "SigIgn:\t%08x\n", p->p_sigignore.__bits[0]);
|
||||
PS_ADD(ps, "SigCgt:\t%08x\n", p->p_sigcatch.__bits[0]);
|
||||
|
||||
/*
|
||||
* Linux also prints the capability masks, but we don't have
|
||||
* capabilities yet, and when we do get them they're likely to
|
||||
* be meaningless to Linux programs, so we lie. XXX
|
||||
*/
|
||||
PS_ADD(ps, "CapInh:\t%016x\n", 0);
|
||||
PS_ADD(ps, "CapPrm:\t%016x\n", 0);
|
||||
PS_ADD(ps, "CapEff:\t%016x\n", 0);
|
||||
#undef PS_ADD
|
||||
|
||||
xlen = ps - psbuf;
|
||||
xlen -= uio->uio_offset;
|
||||
ps = psbuf + uio->uio_offset;
|
||||
xlen = imin(xlen, uio->uio_resid);
|
||||
return (xlen <= 0 ? 0 : uiomove(ps, xlen, uio));
|
||||
}
|
||||
|
@ -175,6 +175,10 @@ linprocfs_allocvp(mp, vpp, pid, pfs_type)
|
||||
vp->v_type = VREG;
|
||||
break;
|
||||
|
||||
case Pprocstat:
|
||||
case Pprocstatus:
|
||||
/* fallthrough */
|
||||
|
||||
case Pmeminfo:
|
||||
case Pcpuinfo:
|
||||
case Pstat:
|
||||
@ -251,6 +255,12 @@ linprocfs_rw(ap)
|
||||
case Pmem:
|
||||
rtval = procfs_domem(curp, p, pfs, uio);
|
||||
break;
|
||||
case Pprocstat:
|
||||
rtval = linprocfs_doprocstat(curp, p, pfs, uio);
|
||||
break;
|
||||
case Pprocstatus:
|
||||
rtval = linprocfs_doprocstatus(curp, p, pfs, uio);
|
||||
break;
|
||||
case Pmeminfo:
|
||||
rtval = linprocfs_domeminfo(curp, p, pfs, uio);
|
||||
break;
|
||||
|
@ -99,6 +99,8 @@ static struct proc_target {
|
||||
{ DT_DIR, N(".."), Proot, NULL },
|
||||
{ DT_REG, N("mem"), Pmem, NULL },
|
||||
{ DT_LNK, N("exe"), Pexe, NULL },
|
||||
{ DT_REG, N("stat"), Pprocstat, NULL },
|
||||
{ DT_REG, N("status"), Pprocstatus, NULL },
|
||||
#undef N
|
||||
};
|
||||
static const int nproc_targets = sizeof(proc_targets) / sizeof(proc_targets[0]);
|
||||
@ -547,6 +549,12 @@ linprocfs_getattr(ap)
|
||||
vap->va_gid = KMEM_GROUP;
|
||||
break;
|
||||
|
||||
case Pprocstat:
|
||||
case Pprocstatus:
|
||||
vap->va_bytes = vap->va_size = 0;
|
||||
/* uid, gid are already set */
|
||||
break;
|
||||
|
||||
default:
|
||||
panic("linprocfs_getattr");
|
||||
}
|
||||
@ -609,6 +617,9 @@ linprocfs_access(ap)
|
||||
case Pself:
|
||||
case Pmeminfo:
|
||||
case Pcpuinfo:
|
||||
case Pstat:
|
||||
case Puptime:
|
||||
case Pversion:
|
||||
break;
|
||||
default:
|
||||
procp = PFIND(pfs->pfs_pid);
|
||||
|
Loading…
Reference in New Issue
Block a user