problem on /proc/self/exe and /proc/num/exe
- From: "William" <snowingbear@xxxxxxxxx>
- Date: 30 Aug 2006 18:20:51 -0700
In my project, I encountered a strange problem. As you know
readlink(2) can be used to get the real running program by
/proc/self/exe. For example:
on RHELU4:
test.c:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main()
{
char elf_file[65536];
pid_t pid;
char string[100];
pid = getpid();
printf("pid is %ld\n", pid);
sprintf(string, "/proc/%ld/exe", pid);
printf("string is %s\n", string);
sleep(20);
if (readlink(string, elf_file, 65536) == -1) {
perror("readlink");
return -1;
}
printf("real file is %s\n", elf_file);
}
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.
.
- Follow-Ups:
- Re: problem on /proc/self/exe and /proc/num/exe
- From: Paul Pluzhnikov
- Re: problem on /proc/self/exe and /proc/num/exe
- From: John Fusco
- Re: problem on /proc/self/exe and /proc/num/exe
- Prev by Date: Re: Building X11R7.1/xorg from source
- Next by Date: Re: problem on /proc/self/exe and /proc/num/exe
- Previous by thread: SIGSEGV handler Question
- Next by thread: Re: problem on /proc/self/exe and /proc/num/exe
- Index(es):
Relevant Pages
|