두 개의 다른 컨텍스트에서 프로세스의 '실행 env'의 차이를 어떻게 알 수 있습니까?프로세스의 실행 환경 이해
질문을 올바르게 발음하려면 /opt/plan9/
에 plan9port가 설치되어 있고 /opt/plan9/bin/fortune
에서 행운 프로그램을 실행하면 문제가 없습니다. (행운의 목록을 /opt/plan9/lib/fortune
과 /opt/plan9/lib/fortune.index
에서 읽음).
char* opts[] = {"fortune"};
execve("/opt/plan9/bin/fortune", opts, NULL);
과 함께 C 코드 (test.c) 내부에서 호출하면 행운의 목록을 읽지 않습니다. 나는이 두 바이너리를 호출 할 때 strace를 사용하여 차이점을 확인했습니다.
open("/usr/local/plan9/lib/fortunes", O_RDONLY) = -1 ENOENT (No such file or directory)
Misfortune!
+++ exited with 1 +++
strace -f -eopen ./test
strace -f -eopen fortune
open("/opt/plan9/lib/fortunes", O_RDONLY) = 3
Snob intellectual bachelors can't have fun in San Antonio. -Ted Nelson
+++ exited with 0 +++
.
./test는 운세 파일을 어떻게 변경합니까? 바이너리가 라이브러리를 읽는 곳에서부터 exec 환경과 관련이 있어야합니다.
두 번째 인수 ('opts')에서 전달 된 배열이'NULL'으로 끝나야하므로 문제가 발생하지는 않지만'execve() '를 올바르게 호출하지 않습니다. –