4

C コードと相互運用しているため、構造体を直接キャストすることができず、Go で同等のものを定義する必要がありました。からのC関数libproc.h

int proc_pidinfo(int pid, int flavor, uint64_t arg,  void *buffer, int buffersize)

の C 構造体flavor==PROC_PIDTASKINFOproc_taskinfo、で定義されているとおりですsys/proc_info.h( に含まれていlibproc.hます)。

struct proc_taskinfo {
    uint64_t        pti_virtual_size;   /* virtual memory size (bytes) */
    uint64_t        pti_resident_size;  /* resident memory size (bytes) */
    uint64_t        pti_total_user;     /* total time */
    uint64_t        pti_total_system;
    uint64_t        pti_threads_user;   /* existing threads only */
    uint64_t        pti_threads_system;
    int32_t         pti_policy;     /* default policy for new threads */
    int32_t         pti_faults;     /* number of page faults */
    int32_t         pti_pageins;        /* number of actual pageins */
    int32_t         pti_cow_faults;     /* number of copy-on-write faults */
    int32_t         pti_messages_sent;  /* number of messages sent */
    int32_t         pti_messages_received;  /* number of messages received */
    int32_t         pti_syscalls_mach;  /* number of mach system calls */
    int32_t         pti_syscalls_unix;  /* number of unix system calls */
    int32_t         pti_csw;            /* number of context switches */
    int32_t         pti_threadnum;      /* number of threads in the task */
    int32_t         pti_numrunning;     /* number of running threads */
    int32_t         pti_priority;       /* task priority*/
};

実際に Go のコードが動いたとしても、C.proc_taskinfo直接使うことはできませんでした。Go 関数は次のとおりです。ここpropertiesOf()に完全なソースがあります。

C 構造体を参照すると、件名に関する最新の質問と同様のエラーが報告されましたcould not determine kind of name for C.proc_taskinfoが、今回は、定義が でインポートされていると確信しています#include

4

1 に答える 1

7

ドキュメントによると

構造体、共用体、または列挙型に直接アクセスするには、C.struct_stat のように、struct_、union_、または enum_ を前に付けます。

を使用しC.struct_proc_taskinfoます。

于 2015-05-29T14:52:34.530 に答える