* /proc fs - anyone had any success reading
@ 1994-08-16 6:30 Gareth Owen
1994-08-26 15:17 ` Peter Thompson
0 siblings, 1 reply; 2+ messages in thread
From: Gareth Owen @ 1994-08-16 6:30 UTC (permalink / raw)
Hi,
I'm trying to use the /proc filesys and associated ioctl calls as found
in proc (4). All I want to do is read out the prpsstruct info to get
some simple process stats. However whenever I attempt any of the ioctl
calls on the open file descriptor I get EANOTTY which doesn't seem very
appropriate to me :-)
fd = open ("/proc/00567", O_RDWR, 0);
ioctl(fd, whatever_command, &p);
Anyone got any ideas...or better still a short working piece of code which
does something similar....
cheers
Gareth
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: /proc fs - anyone had any success reading
1994-08-16 6:30 /proc fs - anyone had any success reading Gareth Owen
@ 1994-08-26 15:17 ` Peter Thompson
0 siblings, 0 replies; 2+ messages in thread
From: Peter Thompson @ 1994-08-26 15:17 UTC (permalink / raw)
Well, I use it all the time (as I'm responsible for dbx here)
and it does work pretty well. Not to say that we haven't
run into a few bugs from time to time, but who hasn't ;-)
Here's a test program that should illustrate briefly how
to set things up. The presumptions here are that the
program is invoked with the pid of a currently running
process, and that the process is owned by the invoker,
or the invoker has su access. Oh yeah, /proc has to be
mounted, else this don't work at all. Oops, now I see
I mentioned that in the test itself. Silly me.
#include <stdio.h>
#include <fcntl.h>
#include <sys/proc.h>
#include <sys/procfs.h>
#include <sys/types.h>
#include <sys/ioctl.h>
main (argc, argv)
int argc;
char **argv;
{
/* assume that /proc is mounted and user specified the pid of the
* running process.
*/
char pidname[32];
int fd;
struct prstatus prstat;
sprintf(pidname, "/proc/%s", argv[1]);
fd = open(pidname, O_RDONLY | O_NDELAY);
ioctl(fd, PIOCSTATUS, &prstat);
printf("The pc at the time of the sample is 0x%lx\n",
prstat.pr_reg.regs[31]);
close(fd);
exit(0);
}
PeterT
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1994-08-26 15:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1994-08-16 6:30 /proc fs - anyone had any success reading Gareth Owen
1994-08-26 15:17 ` Peter Thompson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox