、あなたは次のように実行しているexeファイルのフルパスを取得することができます:例えばのために
# ls -l /proc/<pid>/path/a.out
# ls -l /proc/$$/path/a.out
lrwxrwxrwx 1 root root 0 Nov 24 17:19 /proc/14921/path/a.out -> /usr/bin/bash
このようにして、実行可能なパスを取得できます。例えば:
# readlink -f /proc/$$/path/a.out
/usr/bin/bash
をするために
# readlink -f /proc/<pid>/path/a.out
そしてプログラムで、あなたはこのようにそれを行うことができます:
よりとても便利な方法です
# ./a.out <pid>
:
#include <stdio.h>
#include <unistd.h>
#define BUF_SIZE 1024
int main(int argc, char *argv[]) {
char outbuf[BUF_SIZE] = {'\0'};
char inbuf[BUF_SIZE] = {'\0'};
ssize_t len;
if (argc != 2) {
printf ("Invalid argument\n");
return -1;
}
snprintf (inbuf, BUF_SIZE, "/proc/%s/path/a.out", argv[1]);
if ((len = readlink(inbuf, outbuf, BUF_SIZE-1)) != -1) {
outbuf[len] = '\0';
} else {
perror ("readlink failed: ");
return -1;
}
printf ("%s\n", outbuf);
return 0;
}
それは使い方です
Solaris 11.3 SRU 5.6以上はありますか? –
[psinfo \ _t solarisの複写がそのフィールドに完全なプロセス名を含んでいない可能性があります](https://stackoverflow.com/questions/35888100/psinfo-t-solaris-does-not-contain-full-process-name-フィールド内) –