Reading the symbol table of the currently running executable

Diomidis Spinellis diomidis at ecrcvax.UUCP
Thu Sep 21 20:09:36 AEST 1989


In article <1989Sep14.134546.2497 at newcastle.ac.uk> mccue at turing.newcastle.ac.uk (Dan McCue) writes:
[...]
>    Are there other systems that provide a "system service" for finding
>    the (path)name/load map of the running executable(s)?

The 8th Research Unix Edition provides a method of obtaining a file descriptor
to the text file of a running executable.  The idea is to open the image of
the process in the process file system /proc and send the appropriate ioctl.

#include <sys/proc.h>
#include <sys/pioctl.h>

/*
 * Return a read only file descriptor to the text file of an executable
 * given its process id.  Returns -1 on failure.  (Not tested).
 */
int
pid2fd(pid)
	int pid;
{
	static char fname[1024];
	long result;
	int fd;

	sprintf(fname, "/proc/%d", pid);
	if ((fd = open(fname, 0)) == -1)
		return -1;
	if (ioctl(fd, PIOCOPENT, &result) == -1)
		return -1;
	return (int)result;
}

Diomidis
-- 
Diomidis Spinellis          European Computer-Industry Research Centre (ECRC)
Arabellastrasse 17, D-8000 Muenchen 81, West Germany        +49 (89) 92699199
USA: diomidis%ecrcvax.uucp at pyramid.pyramid.com   ...!pyramid!ecrcvax!diomidis
Europe: diomidis at ecrcvax.uucp                      ...!unido!ecrcvax!diomidis



More information about the Comp.unix.wizards mailing list