Welcome to Soft32 Linux Forums!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Get actual _full_ name of current executable, not via argv..

 
   Soft32 Home -> Linux -> App Development RSS
Next:  access_ok macor  
Author Message
Alex Vinokur

External


Since: Jul 14, 2009
Posts: 2



(Msg. 1) Posted: Tue Jul 14, 2009 7:40 am
Post subject: Get actual _full_ name of current executable, not via argv[0] on
Archived from groups: comp>os>linux>development>apps (more info?)

Hi,

Linux 2.6.18-92.el5

/opt/intel/compiler/bin/intel64/icpc -v
Version 11.0


Is there any way to get actual _full_ name of current executable, not
only via argv[0] in main() program?


Thanks,


Alex Vinokur
Back to top
Login to vote
Grant Edwards

External


Since: Jul 14, 2009
Posts: 3



(Msg. 2) Posted: Tue Jul 14, 2009 9:52 am
Post subject: Re: Get actual _full_ name of current executable, not via argv[0] [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 2009-07-14, Rainer Weikusat <rweikusat.RemoveThis@mssgmbh.com> wrote:
> Alex Vinokur <alexvn.RemoveThis@users.sourceforge.net> writes:

>> Is there any way to get actual _full_ name of current executable,
>
> You can try reading the /proc/self/exe-symlink. But a file can
> have many different names on a filesystem with hard link
> support, so this may or may not help.

The executable may also have zero names. Smile

--
Grant Edwards grante Yow! HUMAN REPLICAS are
at inserted into VATS of
visi.com NUTRITIONAL YEAST ...
Back to top
Login to vote
John Reiser

External


Since: Mar 08, 2009
Posts: 12



(Msg. 3) Posted: Tue Jul 14, 2009 9:52 am
Post subject: Re: Get actual _full_ name of current executable, not via argv[0] [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

>>> Is there any way to get actual _full_ name of current executable,

>> You can try reading the /proc/self/exe-symlink. But a file can
>> have many different names on a filesystem with hard link
>> support, so this may or may not help.

> The executable may also have zero names. Smile

Beginning in Linux 2.6.29, the kernel sets the AT_EXECFN entry of
the ELF auxiliary vector (see /usr/include/elf.h) to the pathname
that was specified to execve(). All Linux 2.x.y kernels put that
pathname into the new address space, but AT_EXECFN documents it.
Most of the time you can also get that pathname via
(1+ strlen(envp[-1+ n_env]) + envp[-1+ n_env])
where envp is the vector of environment variables, and n_env
is their number. Calling putenv(), or otherwise overwriting
the environment vector or environment strings, may invalidate
the expected results.

Independent of how any potential answer is obtained, and independent
of whether the filesystem supports hardlinks, and independent of
whether the potential answer is a rooted or a relative pathname,
there is a race condition. The pathname at the time of execve()
may have designated a different collection of bytes (file) then,
than it does now. It is difficult to prevent such a difference
in all cases. You can come close
if the medium that holds the bytes is physically read-only,
and if the filesystem that holds the bytes is mounted read-only,
and if there are no other mounts of the filesystem that holds the bytes,
and if the mount point, and all its ancestors, also are read-only
and have no conflicting mounts,
and if there are no symbolic links in any of the relevant paths.
That's a lot to ask, and usually it isn't necessary.

One very legitimate use of the pathname is to be the source
for expanding the dynamic string token "$ORIGIN" in DT_RUNPATH,
so that an executable and its associated "private" shared libraries
can be relocated easily in a filesystem. [A Solaris feature copied by
glibc; never documented. glibc trusts readlink("/proc/self/exe",)
in this case.] The AT_EXECFN token also is the perfect place
for a virtualizer program to adjust the environment.

--
Back to top
Login to vote
Grant Edwards

External


Since: Jul 14, 2009
Posts: 3



(Msg. 4) Posted: Tue Jul 14, 2009 10:12 am
Post subject: Re: Get actual _full_ name of current executable, not via argv[0] [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 2009-07-14, Grant Edwards <invalid@invalid> wrote:
> On 2009-07-14, Rainer Weikusat <rweikusat.TakeThisOut@mssgmbh.com> wrote:
>> Alex Vinokur <alexvn.TakeThisOut@users.sourceforge.net> writes:
>
>>> Is there any way to get actual _full_ name of current executable,
>>
>> You can try reading the /proc/self/exe-symlink. But a file can
>> have many different names on a filesystem with hard link
>> support, so this may or may not help.
>
> The executable may also have zero names. Smile

OT: Did you ever wonder why in English the word "zero" is
treated as plural?

"zero names" "one name" "two names" "three names"
^ ^ ^

Is it that way in other languages?

--
Grant Edwards grante Yow! Those people look
at exactly like Donnie and
visi.com Marie Osmond!!
Back to top
Login to vote
Joe Pfeiffer

External


Since: Jul 17, 2006
Posts: 53



(Msg. 5) Posted: Tue Jul 14, 2009 10:12 am
Post subject: Re: Get actual _full_ name of current executable, not via argv[0] on Linux [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Grant Edwards <invalid@invalid> writes:
>
> OT: Did you ever wonder why in English the word "zero" is
> treated as plural?
>
> "zero names" "one name" "two names" "three names"
> ^ ^ ^
>
> Is it that way in other languages?

I'm not a linguist (nor do I play one on TV), but I'll guess that what's
going on is that the singular is a special case.

We're just taken aback because we expect the special cases to occur at
the boundaries Smile
Back to top
Login to vote
Rainer Weikusat

External


Since: Apr 02, 2007
Posts: 158



(Msg. 6) Posted: Tue Jul 14, 2009 11:20 am
Post subject: Re: Get actual _full_ name of current executable, not via argv[0] on Linux [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Alex Vinokur <alexvn RemoveThis @users.sourceforge.net> writes:
> Linux 2.6.18-92.el5
>
> /opt/intel/compiler/bin/intel64/icpc -v
> Version 11.0
>
>
> Is there any way to get actual _full_ name of current executable,

You can try reading the /proc/self/exe-symlink. But a file can have
many different names on a filesystem with hard link support, so this
may or may not help.
Back to top
Login to vote
Måns_Rullgård

External


Since: May 05, 2004
Posts: 84



(Msg. 7) Posted: Tue Jul 14, 2009 11:20 am
Post subject: Re: Get actual _full_ name of current executable, not via argv[0] on Linux [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Grant Edwards <invalid@invalid> writes:

> On 2009-07-14, Grant Edwards <invalid@invalid> wrote:
>> On 2009-07-14, Rainer Weikusat <rweikusat.RemoveThis@mssgmbh.com> wrote:
>>> Alex Vinokur <alexvn.RemoveThis@users.sourceforge.net> writes:
>>
>>>> Is there any way to get actual _full_ name of current executable,
>>>
>>> You can try reading the /proc/self/exe-symlink. But a file can
>>> have many different names on a filesystem with hard link
>>> support, so this may or may not help.
>>
>> The executable may also have zero names. Smile
>
> OT: Did you ever wonder why in English the word "zero" is
> treated as plural?
>
> "zero names" "one name" "two names" "three names"
> ^ ^ ^
>
> Is it that way in other languages?

It is that way in Swedish.

--
Måns Rullgård
mans.RemoveThis@mansr.com
Back to top
Login to vote
David Schwartz

External


Since: Apr 25, 2007
Posts: 134



(Msg. 8) Posted: Tue Jul 14, 2009 12:50 pm
Post subject: Re: Get actual _full_ name of current executable, not via argv[0] on [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Jul 14, 7:40 am, Alex Vinokur <ale....RemoveThis@users.sourceforge.net> wrote:
> Hi,
>
> Linux 2.6.18-92.el5
>
> /opt/intel/compiler/bin/intel64/icpc -v
> Version 11.0
>
> Is there any way to get actual _full_ name of current executable, not
> only via argv[0] in main() program?

The question is incoherent. For example:

If I run '/bin/foo' and then someone does 'mv /bin/foo /bin/bar; mv /
bin/baz /bin/foo' is the "actuall full name of the current executable"
'bin/foo' or '/bin/baz'?

If '/bin/foo' is running and then someone does 'rm /bin/foo', what is
the "actual full name" of the executable?

And so on.

What is your outer problem? The solution is probably not what you
think it is.

DS
Back to top
Login to vote
Alex Vinokur

External


Since: Jul 14, 2009
Posts: 2



(Msg. 9) Posted: Tue Jul 14, 2009 9:46 pm
Post subject: Re: Get actual _full_ name of current executable, not via argv[0] on [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Jul 14, 10:50 pm, David Schwartz <dav....DeleteThis@webmaster.com> wrote:
[snip]
> What is your outer problem? The solution is probably not what you
> think it is.
>
> DS

I need to print full path of executable file to screen/log.

P.S. Answer from other forum:
readlink("/proc/self/exe", buffer, buffer_size);

Alex Vinokur
Back to top
Login to vote
Display posts from previous:   
Related Topics:
How can i register a link protocol for browsers - I want to add an action to the system so that every time a user clicks in a link with for example ..

storing the data in ln2440 target board memory - hai.. i using the target board ln2440sbc..and linux OS.. (16Mb flash and 32Mb sdram) i have cross compiled and porte...

GTK run error - hi i had created one same application in glad interface designer with c option.the n i compiled the same after that i....

C++ -> mplayer, stdin, stdout, popen / fork / pipe... - Hello everybody. I tried to work this out on my own for about 6 hours non-stop now and I just don't get it working.......

[gentoo-user] Hardened Kernel (PaX): How to allow Text Rel.. - Hello! I'm using a Hardened Kernel and set "Disallow ELF text relocations" (CONFIG_PAX_NOELFRELOCS=y). Becau...

[PATCH 3/3] lutimesat: actual syscall and wire-up on i386 - lutimesat(2) does everything futimesat(2) does except it doesn't follow symlinks. It could be used by tar(1) and cp(1)...
       Soft32 Home -> Linux -> App Development All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Categories:
 Windows
  Linux
 Mac
 PDA


[ Contact us | Terms of Service/Privacy Policy ]