what port(s) give me good control over processes (list, kill, etc) better than MacOS pgrep+pkill

Eckard Brauer hangglider at gmx.de
Sat Apr 8 09:47:57 UTC 2023


if I didn't misunderstand UNIX signals too much, there are a few
signals which can't be ignored. That means, after an optional signal
handling routine has been run, the deconstruction and remove of the
specific process is (or should be) enforced by the OS itself. SIGKILL,
SIGSEGV, SIGILL should at least belong to that group.

That's indeed a weak thing at all, as I already found software (some
java versions on HP PA-RISC in that case) which inserted signal
handlers for everything to have the ability to cleanly log problems,
but, while trying to log their state, they tried to allocate some
buffer memory for formatting their stuff, with the single effect to
cause another SIGSEGV in case the available memory already really
exhausted and so the initial signal was SIGSEGV too - effectively
locking the process in a semi-active state.

Beside that, all signals not belonging to that group MAY be ignored, so
trying to kill them can be a no-op intentionally. Best example is the
usual (in bash dialect) 'kill -0 ${PID}' in UNIX scripts to only check
for the existence of the given process (return code in ${?} is either 0
or 1), where that effect is intentionally taken. That means, if one
wants to really kill a process, the use of a given, unignorable signal
is strictly neede, and SIGKILL is the signal intended for that. And
even with sending an unignorable signal, one can't be fully sure to
properly remove the given process, as the example shows, and won't even
need an enemy software for that.

Regarding pgrep and pkill, I don't know Apple's implementations (I'm on
Leopard, it seems not to have them), but I know of implementations in
shell scripts, simply based on ps, grep and kill, so the restrictions
should be the same.

Implementing a proc filesystem could be possible, as Darwin sources are
open (and even that of Mach 2), but I'd rather not underestimate the
effort needed and the risks taken into account, especially under the
circumstances that only few (homegrown) software would make use of it.

E.


> Not seeing that, if this fits your scenario:
> 
> sh-3.2$ open -a TextEdit
> sh-3.2$ pgrep -lf TextEdit
> 68476 /System/Applications/TextEdit.app/Contents/MacOS/TextEdit
> sh-3.2$ pkill TextEdit
> # it went away...
> 
> SIGTERM is (usually) like Quit; SIGKILL is like Force Quit.
> 
> A process may ignore SIGTERM; the signalling process will not be
> informed of that. SIGKILL cannot be ignored; although in some Unix
> implementations, a hang on what's supposed to be fast I/O (like a
> physical disk, or an NFS mount that's "hard" but not "intr") can make
> a process unkillable, at least until the hang resolves, if it does;
> if not, nothing but a reboot will kill such a process. Some
> implementations block SIGKILL on process 1, because process 1 is
> essential and there's no good reason to do that.
> 
> Sometimes the executable in an app bundle does not have the same name
> as the app; but a pgrep -lf could match based on the full path
> includng the app name.
> 
> pgrep or pkill not finding something is not an error, although
> they'll have a return code of one. sh-3.2$ pgrep -lf nosuch
> sh-3.2$ echo $?
> 1
> sh-3.2$ pkill nosuch
> sh-3.2$ echo $?
> 1
> 
> You cannot kill something unless you're root or the same real or
> effective userid as it is; there MIGHT be other restrictions, Apple
> liking to be tricky about security. But if it exists and you're not
> allowed to kill it, that would get an error message:
> 
> sh-3.2$ pkill syslogd
> pkill: signalling pid 161: Operation not permitted
> 
> Other than those cases, I don't have further guesses what's happening.
> 
> 
> > On Apr 7, 2023, at 23:55, Kenneth Wolcott
> > <kennethwolcott at gmail.com> wrote:
> > 
> > Hi Richard;
> > 
> >  Thanks for the info.  I'll look into those.
> > 
> >  I found that a process that I started by using the MacOS open
> > command could be listed by prep but I could not kill it with pkill
> > (silently fails, like a no-op).
> >   
> sh-3.2$ 
> 



-- 
Corona? Ich desinfiziere regelmäßig mit Bier. 
What Corona? I regularly disinfect with beer.


More information about the macports-users mailing list