Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Close *all* file descriptors



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