与C代码互操作,我无法直接构建结构,我被迫在Go中定义一个等效的结构。
来自libproc.h
的C函数是
int proc_pidinfo(int pid, int flavor, uint64_t arg, void *buffer, int buffersize)
flavor==PROC_PIDTASKINFO
中的proc_taskinfo
的C结构为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*/
};
:
C.proc_taskinfo
即使Go代码确实有效,我也无法直接使用propertiesOf()
。 Go函数是could not determine kind of name for C.proc_taskinfo
:完整来源here。
如果我引用C结构,我在#include
上报告了类似的错误:.single-row input[type="radio"] {
display: none;
}
.intro {
display. block;
}
.intro .fa {
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
transform: rotate(-90deg);
-webkit-transition: -webkit-transform 250ms ease-in-out;
-moz-transition: -moz-transform 250ms ease-in-out;
-o-transition: -o-transform 250ms ease-in-out;
transition: transform 250ms ease-in-out;
}
.content {
max-height: 0;
overflow: hidden;
-webkit-transition: max-height 250ms ease-in-out;
-moz-transition: max-height 250ms ease-in-out;
-o-transition: max-height 250ms ease-in-out;
transition: max-height 250ms ease-in-out;
}
.opener:checked+label .content {
display: block;
max-height: 100px;
}
.opener:checked+label .intro .fa {
-webkit-transform: rotate(0);
-moz-transform: rotate(0);
-o-transform: rotate(0);
transform: rotate(0);
}
,但这次我确定定义是用{{{}导入的。 1}}。
答案 0 :(得分:7)
要直接访问struct,union或enum类型,请在其前面加上struct_,union_或enum_,如C.struct_stat中所示。
使用C.struct_proc_taskinfo
。