zsh-users
 help / color / mirror / code / Atom feed
From: "Mark J. Reed" <markjreed@gmail.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: exec
Date: Mon, 3 Jun 2024 10:17:05 -0400	[thread overview]
Message-ID: <CAA=-s3xr_GoeqRRAf+UBQQR8NiOz_Sy6=456SeAq1-+ens1rZA@mail.gmail.com> (raw)
In-Reply-To: <2bb9cec5-1293-4103-a73c-fd2a190cb65d@eastlink.ca>

[-- Attachment #1: Type: text/plain, Size: 2099 bytes --]

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. It's like tail-call optimization in programming languages.

In UNIX, the system call version of exec(2) is how _any_ program is run.
Normally, when you type a command without the *exec* builtin in front of
it, the shell first makes a copy of itself, and then that copy replaces
itself with the program you want, using exec(2). Putting exec in front of
it just causes the shell to skip the make-a-copy step and replace itself
right away.

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.


On Mon, Jun 3, 2024 at 10:11 AM Ray Andrews <rayandrews@eastlink.ca> wrote:

> I've just recently come across 'exec' in a few scripts.  No familiarity
> with it.  Running this:
>
> echo before exec
> exec echo exec itself
> echo after exec
>
> ... I find that whether in a script or a function it zaps the terminal and
> there's no such place as 'after exec'. What are the uses of that?  For
> example the script that starts xfce4 'etc/xdg/xfce4/xinitrc' ends with this:
>
>      exec xfce4-session
>
> ... so 'then what'?  Hard to put the question into words, but I have a
> sort of hanging feeling, I don't know where execution goes.  For that
> matter, neither do the xfce4 people know where it goes.  ( Micro rant: you
> have yer systemd and yer xdg and yer dbus and God knows what else all
> layered on top of each other and nobody knows what's actually happening.)
> The question arises cuz I want to run scripts both just before and just
> after an xfce4 session but nobody knows how that might be done.  Not our
> problem here of course, but if I had some insights into 'exec' it might
> help.  When, where and why do we 'exec' things?
>
>

-- 
Mark J. Reed <markjreed@gmail.com>

[-- Attachment #2: Type: text/html, Size: 2977 bytes --]

  reply	other threads:[~2024-06-03 14:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-03 14:10 exec Ray Andrews
2024-06-03 14:17 ` Mark J. Reed [this message]
2024-06-03 14:42   ` exec Ray Andrews
2024-06-03 14:50     ` exec Eric Cook
2024-06-03 14:54     ` exec Mark J. Reed
2024-06-03 15:16       ` exec Mark J. Reed
2024-06-03 15:29         ` exec Ray Andrews
2024-06-03 15:22       ` exec Ray Andrews
2024-06-03 15:33         ` exec Mark J. Reed
2024-06-03 15:59           ` exec Ray Andrews
2024-06-03 16:06           ` exec Bart Schaefer
2024-06-03 16:23             ` exec Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAA=-s3xr_GoeqRRAf+UBQQR8NiOz_Sy6=456SeAq1-+ens1rZA@mail.gmail.com' \
    --to=markjreed@gmail.com \
    --cc=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).