gpt4 book ai didi

c - 使用 truss 调试 open() 命令调用

转载 作者:行者123 更新时间:2023-11-30 17:51:58 24 4
gpt4 key购买 nike

使用truss -t'open' $(program_call)我得到:

open("command.txt", O_RDONLY|O_NONBLOCK)      = 5
response FIFO file descriptor = -1
// Open call was literally sandwiched between print commands, but its not here?
response FIFO file descriptor = 9
open("response.txt", O_WRONLY|O_NONBLOCK) Err#6 ENXIO
response.txt: No such device or address

问题是,我将文件描述符初始化为 -1,所以我知道 open 调用一定已经成功,因为它更改了变量的值。文件描述符实际上被初始化为 -1,然后在 open 命令调用中以某种方式更改为 9(否则程序将在那里结束),但 open 调用不会出现在 truss 调用中,并且计算机无法识别它已打开。

一些代码:

if ((outfd = open(CMD_FIFO_NAME, O_WRONLY | O_NONBLOCK)) == -1) {
fprintf(stderr, "Client: Failed to open %s FIFO.\n", CMD_FIFO_NAME);
exit(1);
}
printf("RESP_FIFO FILE DESCRIPTOR: %d\n", infd);
/* Open the response FIFO for non-blocking reads. */
if ((infd = open(RESP_FIFO_NAME, O_RDONLY | O_NONBLOCK)) == -1) {
fprintf(stderr, "Client: Failed to open %s FIFO.\n", RESP_FIFO_NAME);
exit(1);
}
else printf("RESP_FIFO FILE DESCRIPTOR: %d\n", infd);

最佳答案

truss -f -t'open,close,read,write' run.sh 足以找到我的错误,其中 run.sh 是一个 bash 文件包含我的程序的正确执行。

关于c - 使用 truss 调试 open() 命令调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16398377/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com