I have a Go function that wraps the proc_name(pid,...) lib_proc.h from lib_proc.h .
This is a complete C prototype:
int proc_name(int pid, void * buffer, uint32_t buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
which can be found here /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libproc.h (at least on my system).
This follows the Go code:
package goproc import "C" import "unsafe" import "strings" type DarwinProcess struct { Process } func (DarwinProcess) NameOf(pid int) string { name := C.CString(strings.Repeat("\x00", 1024)) defer C.free(unsafe.Pointer(name)) nameLen := C.call_proc_name(C.int(pid), name, C.int(1024)) var result string if (nameLen > 0) { result = C.GoString(name); } else { result = "" } return result; }
This code will not compile unless a call to C.free(unsafe.Pointer(...)) and import "unsafe" is removed. DarwinProcess::NameOf(pid) method is only for Mac OS X , and it really works if C.free(...) removed from the code.
In its actual form, after go build , the following error message appears: could not determine kind of name for C.free (and nothing more, this is all the compiler output).
Removing C.free(...) unacceptable to me, I have to find how to properly free the memory allocated with C.CString() .
I am puzzled that, according to the documentation , everything is done correctly. I could not find a solution and did not search here or on the Internet.