Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider exec'ing Argcfile #221

Closed
CGamesPlay opened this issue Aug 4, 2023 · 7 comments · Fixed by #222
Closed

Consider exec'ing Argcfile #221

CGamesPlay opened this issue Aug 4, 2023 · 7 comments · Fixed by #222

Comments

@CGamesPlay
Copy link
Contributor

A small change which would be a bit more hygienic is to exec the Argcfile.sh when it's used.

Consider an Argcfile.sh like this one:

#!/usr/bin/env bash

main() {
    exec bash
}

eval "$(argc --argc-eval "$0" "$@")"

When we run this, it results in a process tree like this one:

$ ps uf
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
ubuntu      2034  0.1  0.0 247380 17112 pts/1    Ss   10:40   0:06 -fish
ubuntu     36428  0.0  0.0   3304     4 pts/1    Sl   11:53   0:00  \_ argc
ubuntu     36430  1.0  0.0   8664  5436 pts/1    S+   11:53   0:00      \_ bash

The feature request is for argc (PID 36428) to use exec when it runs the Argcfile.sh, instead of starting it as a child process. This is minor but would be slightly cleaner.

@sigoden
Copy link
Owner

sigoden commented Aug 4, 2023

@CGamesPlay
I don't understand what you said.

fish runs argc
argc locates Argcfile.sh and runsbash Argcfile.sh
bash does the rest

Which part needs improvement?

@CGamesPlay
Copy link
Contributor Author

Instead of running bash Argcfile.sh as a subcommand, it should exec bash Argcfile.sh. This would replace the argc process with the bash process. The desired process tree would look like this:

$ ps uf
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
ubuntu      2034  0.1  0.0 247380 17112 pts/1    Ss   10:40   0:06 -fish
ubuntu     36430  1.0  0.0   8664  5436 pts/1    S+   11:53   0:00  \_ bash

@sigoden
Copy link
Owner

sigoden commented Aug 4, 2023

Three is no way to get rid of argc process in the ps tree.

Bash is invoked outside of the script, no exec exists.

@CGamesPlay
Copy link
Contributor Author

Yes, bash is invoked by argc as a child process. The request is to exec the process instead of spawning it. Basically, switch to exec instead of status. By using exec, the argc process itself is replaced by bash. Then the Argcfile.sh can exec another bash, resulting in the desired ps tree.

@sigoden
Copy link
Owner

sigoden commented Aug 4, 2023

Does exec return exit statuscode?

@CGamesPlay
Copy link
Contributor Author

No, it actually doesn't return at all. The argc process would be entirely replaced by the target command. However, because the process is replaced in-place, the parent of argc will continue waiting for the new process, and will receive the exit code from the new process once the new process finishes.

@CGamesPlay
Copy link
Contributor Author

Fantastic! Thank you 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants