From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 30799 invoked from network); 23 May 2022 06:43:12 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 23 May 2022 06:43:12 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1653288192; b=B7KycVY3l69yqUF0ycAI1mdf1ssI4CKFSHnX7NS4yXphnYzQ95+6OGozoZhTlxSEKh7BwXlQoa eGgS2owXk/Sw6VROPNGbMfkawSr11Nymi3XYekCFepWDvy04bN7aoxJoOaBCgSG8ioFTbNZkXh g5IyyrK8tC2shZh2/kKx/4caPM2bQEOMnlV+R9zRH8wOa2ztc+7ImzwxgCLC4c6ETSGHFDCWMq c46m5RQ+v66MMdikL+5Zo18w1w57TtCOLJIiirj11LsakX4EK/1PqQJa1/ndR22lEt9qyCIpip nsHiNti5kxTVAhWEqjgZBIfOC6dzaUJy3SPLIpYSEaExmw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay3-d.mail.gandi.net) smtp.remote-ip=217.70.183.195; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1653288192; bh=cA9jdCLOOpHThMVoS0kfCmYZa/QV5Jf5IpNdQShkieo=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:DKIM-Signature; b=cQEYW18qFyhBZtzTQCTE0EbT8GAYkW1ODipA4Y3/JPvV7AeTuoy0GRY5NpTi8bDmZjmEepZQsZ ZvS3ra6uw1sfzBd7Iu0uXWnlYFQh79C4a59m5v+1onRha8OTHDbSRmTahSfMdmLfKwC4mK7ZwN zE3SHKwO5NDepzOfT4TkdEq9w/NlhVPDaKnUi2PYJ5DLyhdIfx5IQsGEBQ4oblWeR12BBB/1ov ROFvETXRZlRlyB2qZMfIjJaGlng31xc8GfAN1UF0i15ZBZJxqlDtisxCHCkCKDgSWjEQYFigih B/gvp7yaN6WjQvwMxGqumu5INl5hcEA5oVnHqxHUuCYsvg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=1Xr4cgTEnXSZVDCc3+gxHTUSuHzMev2DOSgsyWNSapQ=; b=RaReUemUSqnCe1uD9DO/lq7On5 dgeTWrvANzTP0rjfnvZUDkoos9De3NB3jcEDoM4WSVRUscWrBaWOfTH7mu0e+xLHFsoNNQGRkDIT/ n3Jf93LQu/0iPpWNyl9Bsyk6mYtyDkrdq6onq3oet3uysHHZljEFsabTxaKhB1V15EJFGjGYETiuN 2Py8FKjvyHQWhUParHBR62RKXO+p15I7rPDk3lnoVzIL1RhRUbP2WghPJ3c5m+ZlPm5hRXeh97Now KLIhnX6xWmRlws4KmkPS9jSK/B6b3+FHfHVUGMB64dXB0TyIY3AhubCWD8hkH9Hm+3wam9OcNL2ss h4HBwRSQ==; Received: from authenticated user by zero.zsh.org with local id 1nt1mY-000DTM-3V; Mon, 23 May 2022 06:43:10 +0000 Authentication-Results: zsh.org; iprev=pass (relay3-d.mail.gandi.net) smtp.remote-ip=217.70.183.195; dmarc=none header.from=chazelas.org; arc=none Received: from relay3-d.mail.gandi.net ([217.70.183.195]:55989) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1nt1ln-000Cm7-Q5; Mon, 23 May 2022 06:42:24 +0000 Received: (Authenticated sender: stephane@chazelas.org) by mail.gandi.net (Postfix) with ESMTPSA id EC18B60005; Mon, 23 May 2022 06:42:22 +0000 (UTC) Date: Mon, 23 May 2022 07:42:22 +0100 From: Stephane Chazelas To: Bart Schaefer Cc: Zsh Users Subject: Re: Close *all* file descriptors Message-ID: <20220523064222.p6kwduzmsydogf7r@chazelas.org> Mail-Followup-To: Bart Schaefer , Zsh Users References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Seq: 27788 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: 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)" 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