I'm trying to understand the following difference I observed when running commands using sudo and su. I've simplified it to the most simple form.
Consider the following two commands:
su - myuser -c "sleep 600s &"
sudo -u myuser sleep 600s &
When considered with ps axu | grep sudo
, the su command spawns one process for myuser only. Meanwhile sudo command spawns two processes: one as a root with command sudo -u myuser sleep 600s &
and one as myuser with command sleep 60s
This is after running other command within sudo grace period of I think 5-15 minutes when password is not required again. (Otherwise the job would get suspended immediately - this is just to say that is not the situation with the suspended jobs.)
So my questions are:
- Can I make sudo return immediately ('behave' like su) so that no additional process as root keeps hanging in and potentially consuming some memory (however small that amount would be)? Or is this by design and the first process under root account just has to stay there until the actual command being executed exists?
- Is calling su in this way similar to calling sudo with options -l/-s/-i?
Thank you.
krzysztof@Alan: ~$ ▶ uname -a
Linux Alan.local 5.4.0-86-generic #97-Ubuntu SMP Fri Sep 17 19:19:40 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
krzysztof@Alan: ~$ ▶ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal