문제

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/nohuped its started processes?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top