unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Omar Polo <op@omarpolo.com>
To: "Timo Myyrä" <timo.myyra@bittivirhe.fi>
Cc: emacs-devel@gnu.org
Subject: Re: [patch] system_process_attributes for OpenBSD
Date: Sat, 02 Jan 2021 13:30:41 +0100	[thread overview]
Message-ID: <87ft3jplla.fsf@omarpolo.com> (raw)
In-Reply-To: <87v9cfo7o0.fsf@asteroid.bittivirhe.fi>


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	other threads:[~2021-01-02 12:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-01 22:29 [patch] system_process_attributes for OpenBSD Omar Polo
2021-01-02  6:18 ` Lars Ingebrigtsen
2021-01-02  7:29 ` Timo Myyrä
2021-01-02 10:36   ` Omar Polo
2021-01-02 12:16     ` Timo Myyrä
2021-01-02 12:30       ` Omar Polo [this message]
2021-01-02  7:43 ` Timo Myyrä
2021-01-05 19:39 ` Omar Polo
2021-01-07 11:23   ` Lars Ingebrigtsen
2021-01-07 11:30     ` Omar Polo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ft3jplla.fsf@omarpolo.com \
    --to=op@omarpolo.com \
    --cc=emacs-devel@gnu.org \
    --cc=timo.myyra@bittivirhe.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).