From owner-freebsd-hackers Wed Jun 18 16:42:12 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id QAA19501 for hackers-outgoing; Wed, 18 Jun 1997 16:42:12 -0700 (PDT) Received: from watermarkgroup.com (lor.watermarkgroup.com [38.246.139.30]) by hub.freebsd.org (8.8.5/8.8.5) with SMTP id QAA19495 for ; Wed, 18 Jun 1997 16:42:10 -0700 (PDT) Received: by watermarkgroup.com (4.1/SMI-4.1) id AA25334; Wed, 18 Jun 97 19:32:00 EDT Date: Wed, 18 Jun 97 19:32:00 EDT From: luoqi@watermarkgroup.com (Luoqi Chen) Message-Id: <9706182332.AA25334@watermarkgroup.com> To: yifeng@ecsl.cs.sunysb.edu Subject: Re: no subject (file transmission) Cc: hackers@FreeBSD.Org Sender: owner-hackers@FreeBSD.Org X-Loop: FreeBSD.org Precedence: bulk > 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);