- 论坛徽章:
- 0
|
向各位请教在开发中碰到一个很奇怪的问题。有一个hello.c程序,还有一个test.c程序中使用readlink(2)通过/proc/self/exe来获得当前运行程序的,通过gcc test.c -o test -static编译,在ia64,x86_64和i386上都可以正常运行,但是当我在编译hello.c时通过gcc -Wl,--dynamic-linker test hello.c -o hello将test作为linker的时候,在i386和x86_64上用readlink(2)通过/proc/self/exe来获得当前运行程序失败,但在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
修改成通过/proc/pid号/exe来读也是同样的效果。而且通过ll /proc/22239/看是有exe这个文件的,但通过ll /proc/22239/exe来看却报No such file or directory。
附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);
} |
|