15

Why does sudo (among other similar commands) start a new process by calling fork() before exec(), rather than just running the command within the same process? sudo doesn't do anything after it runs the command. (Or does it?)

1 Answer 1

17

If sudo merely called exec, then sudo couldn't have done things like run any cleanup tasks after the exec'd code completed. Take pam_open_session and pam_close_session for example.

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.