2021-10-30 22:01:51 +0700, Robert Elz via austin-group-l at The Open Group:
>     Date:        Fri, 29 Oct 2021 18:13:29 -0700
>     From:        Alan Coopersmith <alan.coopersm...@oracle.com>
>     Message-ID:  <e7c56ee8-2103-63d8-07f4-19a0bd359...@oracle.com>
> 
>   | The SVR4 implementation (inherited by Solaris & illumos) writes white
>   | space before each pid to stdout:
> 
> Thanks, with that, and Geoff's reference to XBD 5 to justify it, this
> doesn't look quite so useless.
> 
> I still believe we'd probably be better off deleting it, than fixing
> the spec though.
[...]

While I agree it's badly designed, it's still useful. And since
lsof is rarely available, that's generally your only option for
this kind of things.

Note that its output is non-text (doesn't end in newline and
could be larger than LINE_MAX), which means that with the
POSIX API, you can't post-process it with text utilities.

fuser /some/file 2> /dev/null | xargs kill

is not guaranteed to work (not to mention it will call kill
without arguments if there's no matching pid).

So, one would need something like:

(fuser /some/file 2> /dev/null; echo) | fold -b | xargs sh -c '
  [ "$#" -ne 0 ] && kill "$@"' sh

If one really wanted to use xargs.

Or:

unset -v IFS
set -- $(LC_ALL=POSIX fuser /some/file 2> /dev/null)
[ "$#" -ne 0 ] && kill "$@"

(using LC_ALL=POSIX because otherwise fuser may surround %d with
blanks other than the ones in $IFS by a strict reading of the
spec).

On most systems, you can do:

fuser /some/file 2> /dev/null | xargs -r kill

(the -r being implicit in some xargs implementations, making
them non-compliant but more sensible).

fuser's stderr output is also hardly post-processable reliably.

-- 
Stephane

  • Anyone know how... Robert Elz via austin-group-l at The Open Group
    • Re: Anyone... enh via austin-group-l at The Open Group
    • Re: Anyone... Robert Elz via austin-group-l at The Open Group
      • Re: An... enh via austin-group-l at The Open Group
        • Re... Alan Coopersmith via austin-group-l at The Open Group
      • Re: An... Alan Coopersmith via austin-group-l at The Open Group
      • Re: An... Geoff Clare via austin-group-l at The Open Group
      • Re: An... Robert Elz via austin-group-l at The Open Group
        • Re... Stephane Chazelas via austin-group-l at The Open Group
          • ... steph...@chazelas.org via austin-group-l at The Open Group
    • Re: Anyone... Garrett Wollman via austin-group-l at The Open Group

Reply via email to