LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-26-2020, 07:32 PM   #1
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,685
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
sudo process


i notice that when running something with sudo, the sudo process remains waiting. maybe sudo needs to do something after the process it started gets finished. does anyone know what this is? i can't explore this with strace since sudo is an suid program.
 
Old 10-26-2020, 07:45 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,363
Blog Entries: 28

Rep: Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149
This article may help. https://www.howtoforge.com/#what-is-a-sudo-session

Here's an excerpt.

Quote:
If you use the sudo command frequently, I am sure you'd have observed that after you successfully enter the password once, you can run multiple sudo commands without being prompted for the password. But after sometime, the sudo command asks for your password again.

This behavior has nothing to do with the number of sudo-powered commands you run, but instead depends on time. Yes, by default, sudo won't ask for password for 15 minutes after the user has entered it once. Post these 15 minutes, you'll be prompted for password again.
 
Old 10-27-2020, 08:00 AM   #3
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,915

Rep: Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033
As a guess, I'd say it's waiting to close the PAM session once the invoked process has completed.
 
Old 10-27-2020, 08:56 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,989

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
that is quite usual: the parent process is waiting for completion [of the child] if that was not started as background process.
 
Old 10-27-2020, 03:09 PM   #5
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,685

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
so the sudo process hangs around in the background for a while so future sudo commands (to the same other user?) don't re-prompt for your password. i thought that feature was a file stored in a place users cannot get to.
 
Old 10-27-2020, 04:12 PM   #6
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
^ I think post #4 has a simpler, more accurate explanation.
 
Old 10-27-2020, 05:49 PM   #7
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,685

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
but waiting will still work if sudo were to directly execv() the program it is to run as opposed to using fork() and having that child do execv() (or whatever) plus all the code/work doing the extra waiting. but if there is something else that sudo code running in the user context still needs to do, that would justify the extra stuff.

my own programming philosophy is "if it's not needed, don't do it".

i'm just curious about sudo. i'm curious to know if something justifies what it is doing or it is just doing it because of the way its developer codes things. i tried to think of how i would implement sudo. but i don't have the experience going through all the design to really know,
 
Old 10-28-2020, 01:43 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,989

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
I just don't understand it. sudo first checks the user, permissions, configs (password if required) and will create the environment for the child process. finally it uses fork and execv (or something similar to start it.
This is how it work: <any process> will do its job and if required uses fork and execv (or something similar) to start child or children. And will wait for the exit code of it (or them). The other way is when the child process is detached.

you can use pstree to see the process tree and all the parent processes are waiting for their children....

Or
are you speaking about using execv without fork? That will destroy the original process and replace it with its child, so in that case the parent has no any chance to continue....

Last edited by pan64; 10-28-2020 at 01:51 AM.
 
Old 10-28-2020, 03:00 AM   #9
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,817

Rep: Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211
If the uid is switched it is cleaner to fork+wait.
1. the process table reflects where the child process comes from.
2. when the child exits, cleanups can be performed (as the correct user).

Quote:
my own programming philosophy is "if it's not needed, don't do it".
This is an argument against systemd. systemd is a smart implementation of a bloated concept.
 
Old 10-29-2020, 01:16 AM   #10
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,685

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Quote:
Originally Posted by pan64 View Post
Or
are you speaking about using execv without fork? That will destroy the original process and replace it with its child, so in that case the parent has no any chance to continue....
unless the parent needs to be there, such as doing more after the child exits, i would bypass the fork so the current process is used instead of having another and having the parent wait for the child. i've done a few programs like that in both C and Python.

but some coders just always follow the fork/exec/wait pattern no matter the purpose.

a thing i did a few days ago runs itself in the background then runs "top" in the foreground. the background part has a synchronous timer and sends a SIGWINCH to "top" to have it update without the drift probably caused by it using a classic sleep pattern instead of a synchronous timer (an extra call to peak at the current time). now my "synctop" command stays right on the top of the minute.

the forking was a little odd on this one because it was the parent doing the "execv" call. the child just went into the sync timer loop.

you gotta know what your processes are doing.
.
 
Old 10-29-2020, 01:35 AM   #11
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,685

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Quote:
Originally Posted by MadeInGermany View Post
If the uid is switched it is cleaner to fork+wait.
how is that "cleaner", what is dirty if you don't?


Quote:
Originally Posted by MadeInGermany View Post
1. the process table reflects where the child process comes from.
why is that needed? how is that information used?


Quote:
Originally Posted by MadeInGermany View Post
2. when the child exits, cleanups can be performed (as the correct user).
what cleanups? as which user?

Quote:
Originally Posted by MadeInGermany View Post
This is an argument against systemd. systemd is a smart implementation of a bloated concept.
what concept?

i still don't see a cause to do what is not needed. of course, there can be cases where more steps are need, such as an arbitrary requirement to tell the user it is done. the parent waits for the child and makes the announcement. or let the shell keep on waiting for that process it forked that did setuid then execvp (probably does use the vp one). many programs do run suid as root and shell have no trouble waiting on them.
 
Old 10-29-2020, 02:15 AM   #12
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,989

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
Quote:
Originally Posted by Skaperen View Post
unless the parent needs to be there, such as doing more after the child exits, i would bypass the fork so the current process is used instead of having another and having the parent wait for the child. i've done a few programs like that in both C and Python.
That is ok.
Quote:
Originally Posted by Skaperen View Post
but some coders just always follow the fork/exec/wait pattern no matter the purpose.
Probably it is true, but this statement is general and actually meaningless/pointless.
Quote:
Originally Posted by Skaperen View Post
i still don't see a cause to do what is not needed. of course, there can be cases where more steps are need, such as an arbitrary requirement to tell the user it is done. the parent waits for the child and makes the announcement. or let the shell keep on waiting for that process it forked that did setuid then execvp (probably does use the vp one). many programs do run suid as root and shell have no trouble waiting on them.
Regarding sudo: you need to check the source code and you will understand why it was implemented this way.
Additionally if you think you know a better way you are always free to realize your solution and publish it.

(systemd is a different issue, do not discuss it here)
 
Old 10-29-2020, 06:39 PM   #13
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,685

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Quote:
Originally Posted by pan64 View Post
That is ok.
Regarding sudo: you need to check the source code and you will understand why it was implemented this way.
Additionally if you think you know a better way you are always free to realize your solution and publish it.
it was a minor curiosity not worth even getting the source code for. i didn't expect this to be so drawn out. i will just forget about it.
 
Old 10-30-2020, 07:27 AM   #14
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,817

Rep: Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211
1. Process
Switching the identity with su or sudo is a security act.
E.g. root switches to user1 and catches her keystrokes.
It should be visible what happens.

2. Cleanup
Say the shell created temporary files in /tmp/
After an exec an installed cleanup handler might still work,
but after a UID change it won't run as the original user.

3. systemd
systemd has a "control the world" concept.
First it is a service starter replacing SysV init scripts.
Then it assimilates syslog, cron, network manager.
Then it will assimilate the remaining services.
Then it will assimilate the desktop.
At the end Linux will have two PIDs: 0 for the kernel and 1 for systemd.
When a user logs in, systemd will open a "systemd OS" box.
 
Old 10-30-2020, 09:28 AM   #15
cynwulf
Senior Member
 
Registered: Apr 2005
Posts: 2,727

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
Ask the developer: https://www.sudo.ws/todd/
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
API for current running process details like process name, process id, amount of memory used anki123 Linux - General 1 01-20-2019 02:06 AM
LXer: The Ultimate Sudo FAQ — To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
Finding the Process ID of a Process While Initiating the Process senthilmuthiah Linux - Newbie 7 04-02-2009 10:37 AM
Restricting Editing in Sudo (Advanced Sudo Question) LinuxGeek Linux - Software 4 11-04-2006 03:20 PM
Sudo without having to type "sudo?" Mitch G Linux - Security 3 09-28-2006 02:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration