Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 了解流程的执行环境_C_Process_Exec_Strace - Fatal编程技术网

C 了解流程的执行环境

C 了解流程的执行环境,c,process,exec,strace,C,Process,Exec,Strace,我如何知道在两种不同的上下文中流程的“执行环境”的差异 为了正确地表达这个问题,我在/opt/plan9/中安装了plan9port,当我从/opt/plan9/bin/fortune运行fortune程序时,它工作正常。(阅读/opt/plan9/lib/fortune和/opt/plan9/lib/fortune.index中的财富列表)。当我从c代码(test.c)内部调用它时 它不读财富榜。我使用strace来查看调用这两个二进制文件时的区别 strace-f-eopen./test o

我如何知道在两种不同的上下文中流程的“执行环境”的差异

为了正确地表达这个问题,我在
/opt/plan9/
中安装了plan9port,当我从
/opt/plan9/bin/fortune
运行fortune程序时,它工作正常。(阅读
/opt/plan9/lib/fortune
/opt/plan9/lib/fortune.index
中的财富列表)。当我从c代码(test.c)内部调用它时

它不读财富榜。我使用strace来查看调用这两个二进制文件时的区别

strace-f-eopen./test

open("/usr/local/plan9/lib/fortunes", O_RDONLY) = -1 ENOENT (No such file or directory)
Misfortune!
+++ exited with 1 +++
给出默认消息“不幸”

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 read fortunes文件。它一定与exec环境有关,二进制文件从那里读取库

调用
execve()
时,显式地设置了
NULL
环境。因此,
fortune
程序可能依赖于某些环境变量来查找
/opt/plan9/…
。在shell提示下键入
env
,找出设置了哪些环境变量。

当调用
execve()
时,您正在显式设置
NULL
环境。因此,
fortune
程序可能依赖于某些环境变量来查找
/opt/plan9/…
。在shell提示下键入
env
,以找出设置了哪些环境变量。

虽然这似乎不是导致问题的原因,但您没有正确调用
execve()
,因为在第二个参数(
opts
)中传递的数组必须以
NULL
结尾。虽然这似乎不是导致问题的原因,您没有正确调用
execve()
,因为在第二个参数(
opts
)中传递的数组必须以
NULL
结尾。相关的环境变量是PLAN9,设置为/opt/PLAN9。调用execve()时是否应该传递它?是的,听起来不错。别忘了用
NULL
项终止环境变量数组。确定,再查询一次。当我生成zsh时,它调用fortune二进制文件,如果无法读取正确的/opt/plan9/lib/fortunes文件,它每次都会输出不幸。如何使zsh像test.c一样工作?我必须设置什么环境变量?知道吗?我对zsh不太熟悉。有些shell要求您导出环境变量,以便其他程序可以看到它们。相关的环境变量是PLAN9,设置为/opt/PLAN9。调用execve()时是否应该传递它?是的,听起来不错。别忘了用
NULL
项终止环境变量数组。确定,再查询一次。当我生成zsh时,它调用fortune二进制文件,如果无法读取正确的/opt/plan9/lib/fortunes文件,它每次都会输出不幸。如何使zsh像test.c一样工作?我必须设置什么环境变量?知道吗?我对zsh不太熟悉。有些shell要求您导出环境变量,以便其他程序可以看到它们。
open("/opt/plan9/lib/fortunes", O_RDONLY) = 3
Snob intellectual bachelors can't have fun in San Antonio.  -Ted Nelson
+++ exited with 0 +++