xt 发帖数: 17532 | 1 现在我有一个soft link
/home/xt/test/bin/a.out -> /home/xt/build/a.out
然后我执行test/bin/a.out,进入/proc/pid/exe,可以看到
exe -> /home/xt/test/bin/a.out
但是我用GNU C的readlink读出来,发现得到的是
/home/xt/build/a.out
我现在需要的是/home/xt/test/bin/a.out
谁知道这个问题怎么解决? |
m*****e 发帖数: 4193 | 2 post your code, will you?
【在 xt 的大作中提到】 : 现在我有一个soft link : /home/xt/test/bin/a.out -> /home/xt/build/a.out : 然后我执行test/bin/a.out,进入/proc/pid/exe,可以看到 : exe -> /home/xt/test/bin/a.out : 但是我用GNU C的readlink读出来,发现得到的是 : /home/xt/build/a.out : 我现在需要的是/home/xt/test/bin/a.out : 谁知道这个问题怎么解决?
|
xt 发帖数: 17532 | 3 //exec_path = new char[SSIZE_MAX];
exec_path = new char[MAX_DIR_LEN];
char buf[40]= { 0 };
ssize_t length;
pid_t pid = getpid();
sprintf(buf, "/proc/%d/exe", pid);
length = readlink(buf, exec_path, 2048);
buf[length] = 0;
if (length < 0) {
printf("Unable to read link '%s':\n", buf);
printf("errno: %d\n", errno);
return NULL;
}
exec_path[ length ]=0;
printf( "exe
【在 m*****e 的大作中提到】 : post your code, will you?
|
m*****e 发帖数: 4193 | 4 the /proc/*/exe points to the real executable too
ln -s /bin/ls
./ls -l /proc/self/exe
lrwxrwxrwx 1 xxx xxx 0 Dec 18 13:28 /proc/self/exe -> /bin/ls
【在 xt 的大作中提到】 : //exec_path = new char[SSIZE_MAX]; : exec_path = new char[MAX_DIR_LEN]; : char buf[40]= { 0 }; : ssize_t length; : pid_t pid = getpid(); : sprintf(buf, "/proc/%d/exe", pid); : length = readlink(buf, exec_path, 2048); : buf[length] = 0; : if (length < 0) { : printf("Unable to read link '%s':\n", buf);
|
xt 发帖数: 17532 | 5 从我这里看,exe指向的是我执行的那个symlink,而那个
symlink指向的是一个executable.
如果我用shell command readlink,得到的是symlink的
路径,但是如果我用GNU C,得到的是最终的executable
路径
【在 m*****e 的大作中提到】 : the /proc/*/exe points to the real executable too : ln -s /bin/ls : ./ls -l /proc/self/exe : lrwxrwxrwx 1 xxx xxx 0 Dec 18 13:28 /proc/self/exe -> /bin/ls
|
m*****e 发帖数: 4193 | 6
I don't think so. Both should point to the real executable.
【在 xt 的大作中提到】 : 从我这里看,exe指向的是我执行的那个symlink,而那个 : symlink指向的是一个executable. : 如果我用shell command readlink,得到的是symlink的 : 路径,但是如果我用GNU C,得到的是最终的executable : 路径
|
xt 发帖数: 17532 | 7 你自己试一试就知道了。
【在 m*****e 的大作中提到】 : : I don't think so. Both should point to the real executable.
|
m*****e 发帖数: 4193 | 8 My second post already told you how to tell.
【在 xt 的大作中提到】 : 你自己试一试就知道了。
|
xt 发帖数: 17532 | 9 反正这不是我得到的结果。我用的是RHEL5.0 x64
【在 m*****e 的大作中提到】 : My second post already told you how to tell.
|
xt 发帖数: 17532 | 10 嗯,我又到一台RHEL4-x64上测试了一下,发现没有这个问题,
/proc/pid/exe和readlink()返回的都是那个executable的路径,
而不是link的路径
看来是Redhat 5本身的问题。
【在 m*****e 的大作中提到】 : My second post already told you how to tell.
|