Date: Wed, 18 Jun 97 19:32:00 EDT From: luoqi@watermarkgroup.com (Luoqi Chen) To: yifeng@ecsl.cs.sunysb.edu Cc: hackers@FreeBSD.Org Subject: Re: no subject (file transmission) Message-ID: <9706182332.AA25334@watermarkgroup.com>
next in thread | raw e-mail | index | archive | help
> 1) How to get the system time and user time, used by a process, in the kernel?
> I have tried to use getrusage() function in the /sys/kern/kern_resource.c,
> but it won't work. I can not reboot the machine successfully. I bet I
> have done something wrong; neither this is not a good way to do it nor I do
> not use it currectly.
Do not call getrusage(), call calcru() instead,
struct timeval utime, stime, itime;
struct proc *p;
...
calcru(p, &utime, &stime, &itime);
...
> 2) How to open a file and write messages into the file in the kernel?
To open a file,
char *path;
struct vnode *vp;
struct nameidata nd;
struct proc *p;
int error;
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, path, p);
error = vn_open(&nd, O_CREAT|FWRITE, 0644);
if (error) {
}
vp = nd.ni_vp;
VOP_UNLOCK(vp);
keep the vp around, that's your handle to the file.
To close it,
error = vn_close(vp, FWRITE, p->p_ucred, p);
To write to it,
error = vn_rdwr(UIO_WRITE, vp, buf, len, 0, UIO_SYSSPACE,
IO_APPEND|IO_UNIT, p->ucred, (int *)0, p);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9706182332.AA25334>
