tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: how to tell if a process is 64-bit
On Sat, Sep 09, 2017 at 05:58:53AM +1000, Matthew Green wrote:
> > In a cross-platform process utility tool the question came up how to
> > decide if a process is 64-bit.
> >
> > https://github.com/giampaolo/psutil/issues/1102
> >
> > What's the best answer for NetBSD?
>
> in C:
>
> internally, just check #ifdef _LP64.
> externally, kvm_getprocs() with KERN_PROC_PID.
>
> in other languages? don't ask me.
I'm asking for a python frontend to the C one.
I came up with this fragment:
#include <kvm.h>
#include <stdlib.h>
#include <sys/sysctl.h>
int main(int argc, char *argv[]) {
int pid, res;
struct kinfo_proc2 *kp;
kvm_t *kvmp = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, NULL);
if (kvmp == NULL)
exit(1);
pid = atoi(argv[1]);
kp = kvm_getproc2(kvmp, KERN_PROC_PID, pid, sizeof(*kp), &res);
if (res != 1)
exit(1);
kvm_close(kvmp);
}
Which part of the structure can I check to find out 32-bitness?
Thanks,
Thomas
Home |
Main Index |
Thread Index |
Old Index