Re: problem on /proc/self/exe and /proc/num/exe



John:

John Fusco wrote:
William wrote:
test.c is compiled by "gcc test.c -o test -static". On ia64,
x86_64 and i386, it's all OK. But if I run test as a ld, compiled with
"gcc -Wl,--dynamic-linker test hello.c -o hello". It will fail on i386
and x86_64, but OK on ia64.

[root@hpc-rm ld]# ./hello
pid is 22226
string is /proc/22226/exe
readlink: No such file or directory
[root@hpc-rm ld]# ./test
pid is 22239
string is /proc/22239/exe
real file is /home/baiwd/ld/test

And on i386 and x86_64, when I "ll /proc/pid[num]/", there is
/proc/pid/exe, but when I "ll /proc/pid[num]/exe", it reports "No such
file or directory". Could you please tell me why? Thank you very much.


Instead of perror("readlink") try perror(string).
I suspect pid_t may have a different size on x86_64. "%ld" is
problematic going between 32-bit and 64-bit.
Thank you. Sorry for not expressing my thought clearly. I want to
use "test" as a faked ld, and in this faked ld, I hope to figure out
which program is running. So I use readlink(2) to get this from
/proc/self/exe or /proc/<pid>/exe. In fact, if I run the program
"test" directly, it's right. But when test is used as a faked ld, there
seems to be some program with /proc/self/exe and /proc/<pid>/exe
[baiwd@hpc-rm ld]$ gcc -Wl,--dynamic-linker test hello.c -o hello
[baiwd@hpc-rm ld]$ cat hello.c
#include <stdio.h>
int main()
{
printf("hello\n");
return 0;
}

[baiwd@hpc-rm ld]$ ./hello
pid is 19738
string is /proc/19738/exe
readlink: No such file or directory
[root@hpc-rm ld]# ll /proc/19738/exe
ls: cannot read symbolic link /proc/19738/exe: No such file or
directory
lrwxrwxrwx 1 baiwd baiwd 0 Aug 31 11:01 /proc/19738/exe
[baiwd@hpc-rm ld]$ ./test
pid is 20088
string is /proc/20088/exe
real file is /home/baiwd/ld/test

William

.



Relevant Pages