[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How to detect whether a process is running, on Linux, in the manner of 'pidof'?
- From: Marco Ricci <m@...>
- Date: Fri, 9 Apr 2021 13:14:21 +0200
Thus spoke Nicholas Joll:
> Surely there's an easier way for me to tell whether a process is
> running than by determining how pidof works and reimplementing its
> C code, myself, in lua.
Are you sure? From my understanding of how Lua is designed, this type of
task – querying the operating system for information on running
processes – is exactly what Lua *doesn't* aim to provide, because the
details of how to do this are highly operating-system-specific, and much
better suited to "application"-specific C code or Lua modules that are
bound to or loaded into your program. Checking a process for liveness,
given a PID, is within scope of luaposix, as already mentioned. However,
locating the correct PID is definitely neither in the scope of the Lua
standard library nor of the luaposix library, as you have also already
experienced. So, if you can't find a ready-made implementation that
suits your needs, then I think it likely that you will have to get your
hands dirty and write quite a bit of code yourself, in C or Lua or both.
So, assuming you do end up implementing the /proc-traversal yourself...
> Well, I know how to do elementary file-handing in lua, but what do
> I seek in /proc?
...you'll likely want to read the man page for proc to understand the
* * *
Really, at this point, I'd argue that doing the traversal yourself and
getting it right is so much more implementation effort than just
shelling out to pidof and taking the performance hit. I can't imagine
a situation – aside from running on a resource-constrained system
like a microcontroller – where this performance hit is so intolerable
that the reimplementation route is worthwhile.
Description: OpenPGP digital signature
- How to detect whether a process is running, on Linux, in the manner of 'pidof'?, Nicholas Joll
- Re: How to detect whether a process is running, on Linux, in the manner of 'pidof'?, Javier Guerra Giraldez
- Re: How to detect whether a process is running, on Linux, in the manner of 'pidof'?, Adrian Perez de Castro
- Re: How to detect whether a process is running, on Linux, in the manner of 'pidof'?, Nicholas Joll