Issue
How can I find a process is owned by which shell?
It is useful as I have a server with multiple logged in users and a few long-running processes, and I want to know which users can I force log-out without stopping their started jobs.
The output of ps
is reporting a TTY, but it is not useful as even after disowning a job, its TTY remains the same. So how can I find out if a user disown
/nohup
ed its started processes?
Solution
You can't find the “owner shell” in the sense you're describing, because there's no such thing. You can find the parent process, which may be a shell; but you can't know whether the shell disowned the job, because that operation is purely internal to the shell.
What you should really do is instruct your users to start long-running programs inside Screen or Tmux. These are somewhat complex programs, but for basic use, they are very simple.
- Start a Screen session by running the command
screen
. - You can run commands inside that session, and they'll keep running even if you log out.
- If you want to log out with a command still running, disconnect from the Screen session by typing Ctrl+A D.
- To reconnect to an existing Screen session, run
screen -rd
. - If you exit the shell inside a Screen session, the session exits.
You could perhaps make a wrapper script around long-running processes that starts screen
automatically.
Answered By - Gilles 'SO- stop being evil' Answer Checked By - Mildred Charles (WPSolving Admin)