Subject: Re: Trying to compile solaris app for netbsd 1.3
To: Tim Rightnour <root@garbled.futureone.com>
From: Nathan J. Williams <nathanw@MIT.EDU>
List: tech-userlevel
Date: 02/16/1998 10:16:28
>I've gotten pretty far.. but there is one part where it is trying to get
>information out of a procfs.  It performs the following:
>
>	   if (ioctl(fd, PIOCPSINFO, &currproc) < 0) {
>	       (void) close(fd);
>	       continue;
>	   }
>I'm not very familiar with procfs, and I couldn't find any other ioctl to map
>this too, so I'm kindof at a loss here. Any suggestions at all as to what I
>could do to make this work would be appreciated.  More code available on
>reuqest.. (There are other problems in this file I need to resolve as well..

	PIOCPSINFO is a Solaris hack to make implementing ps(1)
easy. Any Solaris box should have the appropriate documentation in the
proc(4) man page, but the short version is that it fills in a
structure with about 36 fields with the vital statistics of the
process referred to by the file descriptor. 

	To do the rough analog of this in NetBSD, you need to go
through kvm_getprocs() and kvm_read() to fill in a struct pstats (see
/usr/include/sys/{resource,resourcevar}.h). Your process will have to
be able to read /dev/kmem to do this on a live system, which means
it'll need to be at least sgid kmem. The ps(1) source on NetBSD would
be good place to look for example code. The source to top (from the
ports tree) might also provide insight into getting the appropriate
information under a variety of operating systems.

	Depending on what your application does, you probably don't
need all the fields in the Solaris process-description structure, or
you might need some that are in the Solaris structure but not the
NetBSD one. But hey, this is what hacking is all about..

	- Nathan