title: How to get the session id of the session associated with a terminal?
body: <p>In Linux, each terminal is associated with only one session (a session has one or more process groups, and a process group has one or more processes).</p>
  
  <p>Is there some function (or a command) that takes a tty device file (for example: <code>/dev/tty1</code> or <code>/dev/pts/0</code>) and returns the session id associated with this tty/terminal?</p>