Score:1

Difference in behaviour between su and sudo

cn flag

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:

  1. 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?
  2. 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
Krzysztof J. Obara avatar
cn flag
I've added details to the question.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.