Bash & Shell Scripting (50 Qs)•Part 3: Advanced Text Processing & Production Internals (Senior / Lead)
What is the difference between `exec command` and running `command`?
senior Levelbash-shellAdvanced Text Processing
In Simple Words:
- Running
command: Forks a child process; shell waits for it to finish. exec command: Replaces the current shell process entirely with the new executable!- PID remains identical.
- When
commandterminates, the process terminates; no subsequent lines of the script will ever run! - Used in Docker container entrypoints (
exec "$@") to ensure signals (SIGTERM) propagate directly to the application process as PID 1.