Forced to define Go struct for casting an unsafe.Pointer() to a C struct -
interoperating c code, not able directly cast structure , forced define equivalent 1 in go. c function libproc.h
is
int proc_pidinfo(int pid, int flavor, uint64_t arg, void *buffer, int buffersize)
the c structure flavor==proc_pidtaskinfo
proc_taskinfo
defined in sys/proc_info.h
(included 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 */ uint64_t pti_threads_system; int32_t pti_policy; /* default policy 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 task */ int32_t pti_numrunning; /* number of running threads */ int32_t pti_priority; /* task priority*/ };
even if go code works, not able use c.proc_taskinfo
directly. go function propertiesof()
: complete source here.
if reference c structure, got similar error reported in latest question on subject: could not determine kind of name c.proc_taskinfo
, time i'm sure definition imported #include
.
as per documentation
to access struct, union, or enum type directly, prefix struct_, union_, or enum_, in c.struct_stat.
use c.struct_proc_taskinfo
.
Comments
Post a Comment