How do I know I'm running inside a linux "screen" or not?

Posted by Jun Chen on Server Fault See other posts from Server Fault or by Jun Chen
Published on 2012-04-06T01:17:57Z Indexed on 2012/04/06 17:32 UTC
Read the original article Hit count: 172

Filed under:

The "screen" refers to a program mentioned in How to reconnect to a disconnected ssh session . That is a good facility.

But there is a question I'd really like to know. How do I know whether I'm running inside a "screen"? The difference is:

  • If yes, I know I can safely close current terminal window, e.g., close a PuTTY window, without losing my shell(Bash etc) session.
  • If no, I know I have to take care of any pending works before I close the terminal window.

Better, I'd like this status to be displayed in PS1 prompt so that I can see it any time automatically.

© Server Fault or respective owner

Related posts about gnu-screen