[comp.unix.wizards] a.out pathname

thomas@sky.COM (Jim Thomas) (11/03/88)

I want to append data to an a.out file.  Then I want the executing program
to read the data (which, of course, would have been ignored by the exec
itself).

From an executing program how do I open the a.out file that
was exec'd?  That's easy -- get its pathname.  One way to get that
pathname (i.e., the first argument to execxx, not argv[0]) is to search
process, text, and in-core inode tables to get the inode number plus
major and minor device numbers and then to search the directories in the
corresponding file system.  Too time-consuming.  Is there
a better way?  Is the FIRST argument to execxx squirreled away somewhere?

If someone would suggest how to write a program that would QUICKLY find
the FULL pathname of its exec'd a.out file, regardless which directory
the a.out file happened to be installed in, I'd be grateful.  I'm
currently using SunOS 3.5.

Jim Thomas                            uunet!swan.ulowell.edu!sky!thomas
SKY Computers Inc., Foot of John Street, Lowell, MA 01852 (508)454-6200

guy@auspex.UUCP (Guy Harris) (11/04/88)

>Is the FIRST argument to execxx squirreled away somewhere?

No.

dlm@cuuxb.ATT.COM (Dennis L. Mumaugh) (11/05/88)

In article <395@auspex.UUCP> guy@auspex.UUCP (Guy Harris) writes:
>>Is the FIRST argument to execxx squirreled away somewhere?
>
>No.

Actually, Guy isn't exactly correct.  The  kernel  does  remember
part  of  the  name  of the a.out used in the exec for accounting
purposes.  The last part of the path (i.e. the file name but  not
path   and  directory)  is  saved  in  the  ublock.   The  kernel
accounting writes this and other information into a file  on  the
process's exit.

This information is also in a program's core dump. [Useful if you
find random cores in / ].

But if you mean "Can my process find out the  name  of  the  file
that  was  used  for execution?" Guy is right.  Only if one has a
/proc file system ala System V Release  3.1.1  for  the  3B15  or
Version  8/9  can one get this information and then it isn't easy
and one must be root. [ Of course if you are root, then  you  can
read  /dev/kmem and reverse engineer the exec and find out.  A 45
on the Knuth Scale of difficulty. ]
-- 
=Dennis L. Mumaugh
 Lisle, IL       ...!{att,lll-crg}!cuuxb!dlm  OR cuuxb!dlm@arpa.att.com