emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [patch] system_process_attributes for OpenBSD


From: Omar Polo
Subject: Re: [patch] system_process_attributes for OpenBSD
Date: Sat, 02 Jan 2021 13:30:41 +0100
User-agent: mu4e 1.4.13; emacs 27.1

Timo Myyrä <timo.myyra@bittivirhe.fi> writes:

> [snip]
>
> Yeah, forgot to finish this so its been a while. Seems that the process
> listing is already in emacs so that can be discarded.
>
> But I got following sample program working without using kvm.
>
> #include <sys/types.h>
> #include <sys/sysctl.h>
> #include <err.h>
> #include <stdlib.h>
> #include <stdio.h>
>
> int
> main(int argc, char **argv) {
>   if (argc < 2) {
>     fprintf(stderr, "Must give PID number as an argument!\n");
>     exit(1);
>   }
>   pid_t pid = atoi(argv[1]); /* valid pid */
>   int mib[6] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid, sizeof(struct 
> kinfo_proc), 1};
>   struct kinfo_proc proc;
>   size_t len = sizeof(proc);
>
>   if (sysctl(mib, 6, &proc, &len, NULL, 0) != 0)
>     err(1, "sysctl");
>   printf("pid belongs to command: %s\n", proc.p_comm);
>   return 0;
> }
>
> I'd say above would be prefered as there would be no need to add more
> libraries. I recall the sysctl(8) is intentionally a bit limited but the
> sysctl(2) should give full access.
>
> Timo

Yeah, you're right!  No wonders I got "invalid argument" from sysctl(2),
I was using the wrong mib!  I'll update the patch ditching kvm in favour
of sysctl.  Other than avoid linking to kvm, this allows me to drop that
ugly static variable for the kvm handler.

Thanks!

Omar Polo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]