From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id B241C24A92 for ; Mon, 3 Jun 2024 17:17:39 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1717427859; b=WCnF4DPAjsmIvNOVYTjqHTNzYlXZ1phuBR+IGvi0pjRNEaKIXYCS5/47xcFIILT8RIci4cKc/4 yRYH36HiK/Dbk8xQSBPf6E0UN7fb4AUnLd9MNOQhhujWhMZ+8oeY3IuU6wIVYLmPgiVoK3wOYa CEguVTjPOL6jSpnKmEj3U2Rmae+7xHkQyK4MlE/GHhp0XQs26Mus27T0LNtfU56jXFbkDdOd87 z6tSN8raSb4ecbO8LG+cNBlE+Ui7Se+WR0/6jhHa3vptGnMH+Wm7bgHz177lU4rTron5MQUbgb /6yyppv/P2PwhakwvGltKqYa02LvB1cjl2EM35fm94GaAg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f178.google.com) smtp.remote-ip=209.85.208.178; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1717427859; bh=uYbUJJk42FGlqShYJYmBj/+U3eMcx1Mhq+z+M4pQL8g=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=sVZJF//GzcC/G7obJLpYAqNsyJb4r2I6I/IX9wOn8oUKipw2uvzW0NB03k4OOwm6rsw/AxxsFY OK0Lt2q/y95O3p3dYjxBu2XPOgzdLptKdEF8tHSFq/hWxxZR3zCNwV2SA+qwjAOVyLGgsoJBR3 F2Ap+Z66C9AaIxRHQPuvGcN6A/qfvCjNxSLQ7tXdiWVfNhKEla1g8BqBPai99zIXBfhFzb8QCo jvndbGM0HMc9y8FkzGf8M+VQzKTygAlhhnKnhqxUWcC6hgoKKO2QGip52dj9+TAy3hMIon5uP7 0BVlxmoO9Ww/1GdEr1ab5oimjUjkKpKkB9UL8+Lj5IF5oA==; 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:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=ANGedD3rtss89HdjLLBKedrctHcUguEUY1ocFYkOA6c=; b=GjL8leRu1z9FjpY/8RBkYmujEI 5CpKCcvi9fc3kwg+xgHwzf4j1xRxw2peoJo6BGatXcX1BcS6l88kioW7J3N+cqljXl4fHqkpon/9B egP7KQDfQZ9ZvZkcj9BLFjiAbfsjU9w5J2081+l4IUWa9Wa7ta6gg+eajVcXi9rMAp6o1buRFPGzn HpDaW7RLzD3OzeMTxhw9mtY54ZrbQLqxtvAyIFogHCYozG0ftkIQd+0XRMR5q4DrtkMmzFSei3kv7 gvK8AEWKKx4VGBEH09FiLiHLzWY9QCaHXCcLfmyB3rzBjKFkCh+5dl48pKwQ7ELpVrLIWRU2DJSiG KEKeUb4w==; Received: by zero.zsh.org with local id 1sE9RK-0005ey-QB; Mon, 03 Jun 2024 15:17:38 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f178.google.com) smtp.remote-ip=209.85.208.178; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lj1-f178.google.com ([209.85.208.178]:60780) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1sE9Ql-0004xr-7c; Mon, 03 Jun 2024 15:17:06 +0000 Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2eaa80cb573so26166571fa.1 for ; Mon, 03 Jun 2024 08:17:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717427822; x=1718032622; darn=zsh.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=ANGedD3rtss89HdjLLBKedrctHcUguEUY1ocFYkOA6c=; b=OJ6VJLpPWLFnR5yy9hqHSf5kxaRB88X6tiy+PAZDQbyQ3yehYcVHpCDS7Q10YKgCqM W4DnF0b8z9fVdPfXwO1ZCLJrvB8AIKYfAwSvacEzj0X/gB+05ggb+qPwI2YOurRAgc5J zaQIjHCT6F7bKvPWPaP+ESlPS9tSaCTi6tUMzigdD+EOLJ1Qrhg6y3zOnH5bLxNOlPmc BkHFZMfyhp6Ze+QL9Fw1uWp5PugqCNM7m3uAdgxwhEP4uBSP/kzrKpTrL/Nn8SSb8qZS 9ZYy2+c2msZqxr6s6jabjsF8W5qDe/DrTd0GmD4aEjMAURNAGhOnFG05a7uxelkiGxk8 twVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717427822; x=1718032622; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ANGedD3rtss89HdjLLBKedrctHcUguEUY1ocFYkOA6c=; b=vT9QBNU1SusWOpl2o6zOpbYir0WnBaMkbyIR/BzUuPSyl8KPSMFrv8RKRSFLjsbWbm eDmifFhBd6OdiRI4NZueAPrnCOXShakhdC6xUjGSi875MWiGiJa8dXdw9pbRbANYQT7L AnPwwh4GSoqmeDSaJCYwSQmzwwonFmWrI09w9T4rlCXlRm3bT0fNG3CpnDlBJ0TtCQN1 5A3R2mIqKZrAdE5+Iq47a8aN4o5paS1KxkqNzzpq8XC2HoETjdg9/B5TIkeh63QGHJm6 6faMtttytQpnGSDHripHt8eIVCr/gumYuhXJy2/HZ4WXPhBKz4VG82swsbH/JcBZTArD FFdQ== X-Gm-Message-State: AOJu0YwIrrv/9J76ur0bdlSw2X42BlcjSiAtwprUzs2SkMw1+90WvlCu o9Ib4PgNii0B3T2utXNv/uXKL1F79AzfoWrO+3GkfHV+YzAnqROxeuDI1ZxlcrRE3n757bc/SQw dFPbPknWjTEn6W6U24/rpnr8Bnp3Y3HAp X-Google-Smtp-Source: AGHT+IFHx+gyoGhhcMopxkiSWC/dfFxTytyMxievmGP00ZRIuajwFm2ki4XAuXfiYOtOgrlP1oOAIxhiuwztphrQBoY= X-Received: by 2002:a2e:95c8:0:b0:2e1:7acb:6c40 with SMTP id 38308e7fff4ca-2ea95121b7dmr62519101fa.29.1717427821474; Mon, 03 Jun 2024 08:17:01 -0700 (PDT) MIME-Version: 1.0 References: <2bb9cec5-1293-4103-a73c-fd2a190cb65d@eastlink.ca> In-Reply-To: From: "Mark J. Reed" Date: Mon, 3 Jun 2024 11:16:49 -0400 Message-ID: Subject: Re: exec To: zsh-users@zsh.org Content-Type: multipart/alternative; boundary="00000000000039fd9e0619fdd3f4" X-Seq: 29984 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: --00000000000039fd9e0619fdd3f4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jun 3, 2024 at 10:54=E2=80=AFAM Mark J. Reed = wrote: > Eahat's the terminal supposed to do with nothing running in it anymore? > That was a rather creative typo for "What" at the start of that question. := ) > Exec has the same impact on the shell as *exit* - shell go bye bye - it > just leaves another program in its place. > In your tests, that other program is *echo*. Since that's a builtin, things are a little different. In bash or ksh, *exec* only works on external programs, so if you type *exec echo*, you'll be running */bin/echo* or */usr/bin/echo* (or wherever the binary lives) instead of the shell builtin. But in Zsh, *exec*'ed builtins are still builtins; the shell simulates the effect of *exec* by exiting after it executes the builtin command. So *exec echo whatever* is just a shorter way of writing *echo whatever; exit*. But if you *exec* an external program that takes a while to run, say *exec sleep 300*, then you can run *ps *in another window and see that the shell from which you launched the *sleep* is no longer there; the *sleep* has replaced it. In fact, you can see that the process ID formerly belonging to it has been taken over: Window 1: *zsh% echo $$* *42566* *zsh% exec sleep 300* Window 2: *zsh% ps -fp42566* *UID PID PPID C STIME TTY TIME CMD* * 501 42566 42383 0 11:05AM ttys003 0:00.11 sleep 300* > Mark J. Reed > > > On Mon, Jun 3, 2024 at 10:42 Ray Andrews wrote: > >> >> >> On 2024-06-03 07:17, Mark J. Reed wrote: >> >> The *exec* builtin replaces the running shell with whatever program you >> run. The point is to avoid clogging the process table with shells that = are >> just hanging out waiting to do nothing but exit as soon as their child >> process finishes. >> >> I get that. >> >> >> In your case, the script exists to set things up in the environment and >> then run xfce4-session; there's nothing for it to do after xfce4-session >> completes, so it uses *exec* to tidy up. >> >> >> Sure. But then what? I understand that if a script or function has >> nothing more to do, it may as well pre-kill itself. But the difference i= s >> that 'exec' kills the entire terminal, it doesn't just return to the pro= mpt >> in a more efficient way -- which would be easy to understand, as above. >> exec seems to pull the rug out from under itself, not just end a script >> more efficiently. In my case, from what I've heard control seems to pas= s >> to dbus. Mind, if dbus called the script then that's what one might >> expect. >> >> >> --=20 Mark J. Reed --00000000000039fd9e0619fdd3f4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, Jun 3, 2024 at 10:54=E2=80=AFAM M= ark J. Reed <markjreed@gmail.com<= /a>> wrote:

That was a rather creative typo for "What" at the start o= f that question. :)
=C2=A0
=C2=A0Exec has the same impact on the sh= ell as exit - shell go bye bye - it just leaves another program in i= ts place.=C2=A0

In your tests, th= at other program is echo. Since that's a builtin, things are a l= ittle different. In bash or ksh, exec=C2=A0only works on external pr= ograms, so if you type=C2=A0exec echo, you'll be running=C2=A0/bin/echo=C2=A0or /usr/bin/echo=C2=A0(or wherever the binary li= ves) instead of the shell builtin. But in Zsh, exec'ed builtins = are still builtins; the shell simulates the effect of exec=C2=A0by e= xiting after it executes the builtin command. So exec echo whatever= =C2=A0is just a shorter way of writing echo whatever; exit.=C2=A0

But if you exec an external program that take= s a while to run, say=C2=A0exec sleep 300, then you can run=C2=A0= ps in another window and=C2=A0see that the shell from which you launche= d the sleep=C2=A0is no longer there; the sleep=C2=A0has repla= ced it. In fact, you can see that the process ID formerly belonging to it h= as been taken over:

Window 1:
zsh% echo $$
=
42566
zs= h% exec sleep 300

Window 2:
<= b>zsh% ps -fp42566
=C2=A0=C2=A0UID =C2=A0 P= ID =C2=A0PPID =C2=A0 C STIME =C2=A0 TTY =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = TIME CMD
=C2=A0 501 42566 42383 =C2=A0 0 11:05AM ttys003 =C2=A0 = =C2=A00:00.11 sleep 300



On Mon, Jun 3, 2024 at 10:42 Ray Andrews = <rayandrews@= eastlink.ca> wrote:
=20 =20 =20


On 2024-06-03 07:17, Mark J. Reed wrote:
=20
The=C2=A0exec=C2=A0builtin replaces the run= ning shell with whatever program you run.=C2=A0 The point is to avoid clogging the process table with shells that are just hanging out waiting to do nothing but exit as soon as their child process finishes.
I get that.=C2=A0


In your case, the script exists to set things up in the environment and then run xfce4-session; there's nothing for it to do after xfce4-session completes, so it uses exec= =C2=A0to tidy up.

Sure.=C2=A0 But then what? I understand that if a script or function ha= s nothing more to do, it may as well pre-kill itself. But the difference is that 'exec' kills the entire terminal, it doesn&#= 39;t just return to the prompt in a more efficient way -- which would be easy to understand, as above.=C2=A0 exec seems to pull the rug out from unde= r itself, not just end a script more efficiently.=C2=A0 In my case, from what I've heard control seems to pass to dbus.=C2=A0 Mind, if dbus = called the script then that's what one might expect.=C2=A0




--
Ma= rk J. Reed <mar= kjreed@gmail.com>
--00000000000039fd9e0619fdd3f4--