Understand TTY and parent/child process handling in su-exec
masterA key advantage of su-exec is how it handles process hierarchies. Traditional tools like su execute the target command as a child of a shell, which can cause issues with signal propagation and TTY ownership. su-exec executes the command directly as the primary process (PID 1 in many container contexts).
Comparison Example:
Using su (where the shell becomes the parent of the command):
$ docker run -it --rm alpine:edge su postgres -c 'ps aux'
PID USER TIME COMMAND
1 postgres 0:00 ash -c ps aux
12 postgres 0:00 ps auxUsing su-exec (where the command is executed directly):
$ docker run -it --rm -v $PWD/su-exec:/sbin/su-exec:ro alpine:edge su-exec postgres ps aux
PID USER TIME COMMAND
1 postgres 0:00 ps aux