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 14081 invoked from network); 21 May 2022 20:03:27 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 21 May 2022 20:03:27 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1653163407; b=FkFTl3xSbg+8X18Coo942FB70yu6rb7biXuChUj/t+DIY/zgLSRew/eTbInBhTQAbboe/HpTht 2I7/pTziK4HTjUdLqpLnZO6fQ2bknzFoDREi5iym12DpNkGnKiEVeX0p/76J2hcg3fM6Kr/7rG a5DfPu2gauz6PYAu9ceont+6xJVNs6XWVmRCVyiddl9JXnfnkZ4eSpgKbA8wLZGCRAzlOSZiq+ xNWYr4QyPti1CGgpQ7cy70yQEp8YyJa/W1ABBgNpY8O59Z0/ocgOznlRX0TDfUJG3o3mrzDlNx i2M4jpoammDIIW80AaCyfErlQZgqiAybf7TaPrBxHdyGeQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f51.google.com) smtp.remote-ip=209.85.218.51; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1653163407; bh=cK3psdsGsg6LC7GdKLJYoS2ne2NPbwJ3WVAziHsFh0o=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=Vt4QlkDMwX0gztrBkMvI1BMLY+qyK/TqSZH4HuwsiqGpS1sAZm4PsUK/raTfr7JuRPWodGxk5W oJY1Kfp2rLmv4Mcfp23mnaIhr2RF72cd9fieiOtiwQxmmV8EsMYcb1MP1wD51WdRyE1NbUzSLG bHupr2YqOFXHhtX32zzGzy4ElAgL7dvDqBVd1I4pmjYleB6VYp0KbIEYWp8FLB9i3mHKcSpmMy d4jKQJfZnLHtfGNj9Ep9pSR06HkGGBPu2Z2r5zY0tmT4AdYlKczhqggSIeEA1ZCVNkcbIyAvMt GY6TipMwCHpAuySQ+ThiUWuADT6yDa7AXzrjwnDz2JNN1w==; 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:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=K/MC7XhXtTthZKIVKOluQsyLuFSlfeLcAQZr/UCHyYc=; b=GfUymORox24Pmdnl2BOHK3O329 ypm6FSEQ6aFAeRSaF6IgMTdfnF1MPiP06z3ig9GtGNoX1NmpdDIbtBl7qoWfVxUNluY3/LSh9CjzM EsN+EDpCyMudODsQuF3cGPVXyzl560Mg40fzusdgKo2BYNxGXHl4eYNNlhnCFbX579q8tK0AYXEim nNFlRz3qsGAMQQL0YR0WVXOXO+L/6wFL30VXc1uPvTOdeRA/dL2zWGQrn30ikFdsCiFWW1n9ceoz4 K+pkn0Z0tmi+ZncARknxYJIxS0B6fBBb2FcFKqlmXhCsywkBR0iWg32pC4/z+7S+u12bgWO4UXliC awrp+YzA==; Received: from authenticated user by zero.zsh.org with local id 1nsVJt-0005iL-6q; Sat, 21 May 2022 20:03:25 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f51.google.com) smtp.remote-ip=209.85.218.51; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f51.google.com ([209.85.218.51]:36432) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1nsVIz-0004y1-V7; Sat, 21 May 2022 20:02:31 +0000 Received: by mail-ej1-f51.google.com with SMTP id gi33so12892199ejc.3 for ; Sat, 21 May 2022 13:02:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=K/MC7XhXtTthZKIVKOluQsyLuFSlfeLcAQZr/UCHyYc=; b=urX4p9fFbc37uNuY/1W2I+7lUOcgQaIwuvJo193EQiLUWG8F6iZrB97VQJwC2S3ENA nP9+TyZPxY1GR+LGqqFiHvNyZ+kvFXSpxEkIT3fNxdGK4pem9x3iTPlkHxgX0+/BbAgz fmMmwOKTIL19+d7s2Tii/+I84f+gk6CjI3uYohVtOXOC0Y4dlF0VOjEG9yXqLIEbCg8h 1aInPzQHGVvNf1QCkSsdCs6dA0LtGCgbMd9++EV6E9bFJ8fvMquwA/VfXLsnz3tIOkgq Li5k7QhR+bSlMGzz9N9Z5n/Sic0FElf1PY43xiJ9D0M2HwvDYGYzUUjtCpQ4T2sShI+V HPAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=K/MC7XhXtTthZKIVKOluQsyLuFSlfeLcAQZr/UCHyYc=; b=esmrovwSvrhb3K7FOjmbTKvWrws4bl5FOTKGPOEPdVi2QHSoydEatyU3R/mPFpmcPQ Fs6gcEnS3VVpVaXz+xO1eqf+Lf8DALSClnM59lFUQYZxGAsRS2BVrfmzpSl+wY0qGDhR 2WcYAqfIIVLyuzG66xd36EXP1QrOipsdABRvPe9WmVXceojS0Lr88GfCsnTWF2w52ALE H98AH4VZU9GtfR4OOBBpQDMJQxXxtuizN6Qunv9KBFdinNHhNZaqypx0EhSOcHiixe6I yRxFA5U4ExkT+04L8fqi5MyJG2TS7DhbqocWNtmhIQ0ESdrRYFSGvtIasDRFsUKAh6zF Ht1w== X-Gm-Message-State: AOAM531Eu1+FP6cSbOyMEH4h9aw2a10jnbUza9z+nCBXR48Cbp9wCKjS BNpuHE3rl0ulxg/gpxnVDOAuxH5lbVMRyjJ8J7+0Hw== X-Google-Smtp-Source: ABdhPJy43wAnaBYqVAioTfXnEHTc/JnU36DAMPoCjK1s5cEgjtOHSExdLXe0C2Bf/aQ9VSx93ipWfCWJ2ZyekvoNHDY= X-Received: by 2002:a17:907:62a0:b0:6fe:69f3:88de with SMTP id nd32-20020a17090762a000b006fe69f388demr13239661ejc.214.1653163349236; Sat, 21 May 2022 13:02:29 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Sat, 21 May 2022 13:02:17 -0700 Message-ID: Subject: Re: Close *all* file descriptors To: Zach Riggle Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 27780 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: On Fri, May 20, 2022 at 11:32 PM Zach Riggle wrote: > > This is probably an usual request, but is there any way to close (or redirect to /dev/null) all open file descriptors known / opened by zsh? I expected this to work if you have /proc/: opened=(/proc/self/fd/*(:t)) wanted=(0 1 2 10) for close in ${^${opened:|wanted}}; exec {close}>&- But zsh temporarily opens a file descriptor (for xtrace output, I believe) during the assignment to $opened, and it's not possible to predict what number that descriptor will have, which means one of those exec is going to error on bad file descriptor and kill the loop. So ... the following seems to be pretty good, though on repeated tries I have sometimes seen descriptors remain open: integer close for close in /proc/self/fd/*(:t); [[ -h /proc/self/fd/$close && ! -t $close ]] && exec {close}>&- > Is there a way to close all of them in a concise way that does not affect e.g. shell pipelines and redirection (i.e., stdout and stderr)? No guarantees about that. If there are descriptors open for temporary files, etc., that are needed by coproc or whatever, this could break it.