【问题标题】:Debugging open() command call with truss使用 truss 调试 open() 命令调用
【发布时间】:2013-04-30 04:28:51
【问题描述】:

使用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 手册页的注释部分注意到这一点:“多个进程或多线程进程(包含多个 LWP 的进程)的跟踪输出不是按严格的时间顺序生成的。例如,read() on可以在相应的write()之前报告一个管道。对于任何一个LWP(传统进程只包含一个),输出是严格按时间排序的。”
  • 是的,但不管打开的调用没有被执行。这不是顺序。它实际上没有被执行。
  • 我在您的其他问题中留下了修复建议。

标签: c unix file-io sparc truss


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-22
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    相关资源
    最近更新 更多