From owner-freebsd-hackers@FreeBSD.ORG Mon Sep 13 12:50:02 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7505D16A4CE for ; Mon, 13 Sep 2004 12:50:02 +0000 (GMT) Received: from gandalf.online.bg (gandalf.online.bg [217.75.128.9]) by mx1.FreeBSD.org (Postfix) with SMTP id E006D43D41 for ; Mon, 13 Sep 2004 12:50:00 +0000 (GMT) (envelope-from roam@ringlet.net) Received: (qmail 32326 invoked from network); 13 Sep 2004 12:47:38 -0000 Received: from unknown (HELO straylight.m.ringlet.net) (217.75.134.254) by gandalf.online.bg with SMTP; 13 Sep 2004 12:47:38 -0000 Received: (qmail 39006 invoked by uid 1000); 13 Sep 2004 12:50:30 -0000 Date: Mon, 13 Sep 2004 15:50:30 +0300 From: Peter Pentchev To: Joanna Sledzik Message-ID: <20040913125030.GA839@straylight.m.ringlet.net> Mail-Followup-To: Joanna Sledzik , freebsd-hackers@freebsd.org References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Nq2Wo0NMKNjxTN9z" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.6i cc: freebsd-hackers@freebsd.org Subject: Re: struct proc - basic question X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Sep 2004 12:50:02 -0000 --Nq2Wo0NMKNjxTN9z Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Sep 13, 2004 at 02:01:39PM +0200, Joanna Sledzik wrote: > Hi :) > I'm very very begginer in Unix system programming. > What function should I use to catch the struct proc for some process? > Is it possible to get the pointer to struct proc using for example the > pid_t pid as an argument? Yes, the function you are looking for is #include struct proc *pfind(pid_t pid) You pass it a pid_t argument and it returns a pointer to a proc structure. However, note that the pfind() function is only available to code running in kernel space - it has to be invoked either from a kernel module, or from code compiled into the kernel itself. If you want to get a process's struct proc from a user-space program, there are two ways to go about it: - use libkvm to muck around the kernel's memory: this is a pretty bad approach for most cases, especially as the kernel's internal structures may change even as you try to examine them and follow the list pointers. If you choose this approach, take a look at the kvm(3) manual page, and note that you need to look for the 'allproc' list, which is usually a singly-linked list, but see for details. - use the sysctl(3) interface to fetch the value of the kern.proc.all sysctl. It is a snapshot of the current process info, see the kinfo_proc structure and the comments around it in the file for more information. G'luck, Peter --=20 Peter Pentchev roam@ringlet.net roam@cnsys.bg roam@FreeBSD.org PGP key: http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint FDBA FD79 C26F 3C51 C95E DF9E ED18 B68D 1619 4553 If the meanings of 'true' and 'false' were switched, then this sentence wou= ldn't be false. --Nq2Wo0NMKNjxTN9z Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (FreeBSD) iD8DBQFBRZeW7Ri2jRYZRVMRAnaVAKCTwF7LoaEGSt6oLXYG6/GAM/MGmQCgtet9 fNgiz7pbIRX6YSUqls1YD5E= =ecit -----END PGP SIGNATURE----- --Nq2Wo0NMKNjxTN9z--