Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Close *all* file descriptors
- X-seq: zsh-users 27788
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Close *all* file descriptors
- Date: Mon, 23 May 2022 07:42:22 +0100
- Archived-at: <https://zsh.org/users/27788>
- In-reply-to: <CAH+w=7YZK2WYTEjgAmb-tT8bVKr631wZr=H_Jx+SKUqsQ6CYNg@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- Mail-followup-to: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- References: <CAMP9c5m72agiGTgWwpi6JGTOsTuH58MGtiG7gJ+n01ey_iXd3A@mail.gmail.com> <CAH+w=7ZD9eHt-+AdVanOJru7r0JqDnT+FYqE5LRor2wt_bS8Bw@mail.gmail.com> <CAMP9c5kJ-zf1-Kyj0Px6dcXA9usPx_jcHN+M=0Y_uPfMNnC=sQ@mail.gmail.com> <YoqMZqv4XiIqPP1n@gmx.de> <YoqT4V1FqHZJzXK5@gmx.de> <CAH+w=7YZK2WYTEjgAmb-tT8bVKr631wZr=H_Jx+SKUqsQ6CYNg@mail.gmail.com>
2022-05-22 16:23:05 -0700, Bart Schaefer:
[...]
> Or even: ${${(M)$(lsof -p $$ -F F):#f<->*}#f}
>
> Curiously, despite the man page for lsof asserting that PID filters
> are applied first, if you add a -d filter to include only certain
> types of descriptors, you get the descriptors for every process.
[...]
You also need -a for "and" (default being "or"):
lsof -w -Ff -p $$ -a -d 3-999999 | sed -n 's/^f//p'
(-F F would be "F file structure address (0x<hexadecimal>)"
according to the manual, I need -F f for fds here).
Here, doing:
sh -c 'exec lsof -w -p "$$" -Ff -ad3-999999' | sed -n 's/^f//p'
Would filter out the fds that have the close-on-exec flag (as
I'd expect would be the case for the internal fds of zsh which
we don't want to close).
(would also filter out the ones created by the user with
sysopen -o cloexec and might list internal sh fds).
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author