【问题标题】:Calculating time taken for interprocess communication计算进程间通信所花费的时间
【发布时间】:2013-06-17 05:48:24
【问题描述】:

在 Linux 中,如果我有两个进程使用可以相互通信的 C 程序(通过 shm、socket、管道等),我如何测量进程在 C 中通信所花费的时间??

即给定进程 A 和 B,A 发送消息,B 读取消息,MB 是某种用于通信的消息框,我希望测量 A 将消息放入 MB 以及 B 检索消息所花费的时间来自 MB。

【问题讨论】:

    标签: c linux


    【解决方案1】:

    在消息队列的情况下,每个消息队列都有一个唯一的 msg 队列 ID。并具有类型为 struct msquid_ds 的关联数据结构,在 中定义, 包含以下成员:

    struct ipc_perm msg_perm;

       ushort msg_qnum;         /* no of messages on queue */
    
       ushort msg_qbytes;       /* bytes max on a queue */
    
       ushort msg_lspid;        /* pid of last msgsnd call */
    
       ushort msg_lrpid;        /* pid of last msgrcv call */
    
       time_t msg_stime;        /* last msgsnd time */
    
       time_t msg_rtime;        /* last msgrcv time */
    
       time_t msg_ctime;        /* last change time */
    

    您可以访问 msg_stime 了解上次消息发送时间和 msg_rtime 了解上次消息接收时间。

    【讨论】:

      【解决方案2】:

      将时间,例如gettimeofday的结果放入消息前导码中,用接收端的时间来衡量差异。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-09-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多