Date: Mon, 13 Sep 2004 15:50:30 +0300 From: Peter Pentchev <roam@ringlet.net> To: Joanna Sledzik <asledzik@ae.katowice.pl> Cc: freebsd-hackers@freebsd.org Subject: Re: struct proc - basic question Message-ID: <20040913125030.GA839@straylight.m.ringlet.net> In-Reply-To: <Pine.OSF.4.58.0409131355160.185678@sulu.ae.katowice.pl> References: <Pine.OSF.4.58.0409131355160.185678@sulu.ae.katowice.pl>
next in thread | previous in thread | raw e-mail | index | archive | help
--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 <sys/proc.h> 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 <sys/proc.h> 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 <sys/user.h> 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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040913125030.GA839>