Author Topic: How to natively get process ID of an external program?  (Read 857 times)


  • Full Member
  • ***
  • Posts: 172
Re: How to natively get process ID of an external program?
« Reply #15 on: December 22, 2022, 09:45:40 am »
[…] an external command-line program. […]
Do you have control over this program? Because some applications use the pidfile pattern, i.e. the program (usually some kind of daemon) writes its PID to a known location (and later deletes the pidfile).

If by "control" you mean 'I started it running', then yes.  If you mean 'I am the super-user monitoring and controlling all functions of this particular piece of kit', then no, that's why I wrote a GUI to interface with it. 

Either way, I must apologize for my naïve assumption that when a file shows up via 'ps -A' with a certain PID, that PID is stuck with it for life.  By "life" I mean "since the last time it was started".  Some folks apparently think it means something different.  Reading around the interwebs, it would seem that PID associations are as ephemeral as mayflies.  In common practice though, I have found 'ps' proven itself reliable enough that a 'kill' command to take down a wayward bit of software via its reported PID will do exactly what it says on the tin, fringe cases be damned.

And with that, I must get back to my previously scheduled programming...
All children left unattended will be given a mocha and a puppy.

Arch (though I may go back to Debian)| FreePascal 3.2.2 + Lazarus 2.2.4, GTK2+ and Qt.  Mostly Qt...


TinyPortal © 2005-2018