与C代码交互操作时,我无法直接转换一个结构,我被迫在Go中定义一个等价的结构。来自libproc.h的C函数是
int proc_pidinfo(int pid, int flavor, uint64_t arg, void *buffer, int buffersize)flavor==PROC_PIDTASKINFO的C结构是在sys/proc_info.h中定义的proc_taskinfo (由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导入的。
发布于 2015-05-29 14:52:34
https://stackoverflow.com/questions/30531721
复制相似问题