Find the answer to your Linux question:
Results 1 to 6 of 6
Hi people, I am a little bit new to Linux and I am interested in following. Imagine we have "process 1" running in "session 1". And also we have "process ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2012
    Posts
    5

    session ID


    Hi people, I am a little bit new to Linux and I am interested in following.

    Imagine we have "process 1" running in "session 1".
    And also we have "process 2" running in "session 2".

    My question is: is it possible that "process 2" obtains the session identifier of "process 1" ???

    thank you.

    it would be desirable to know, if yes, how.

    thank you once again.

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,356
    Hi and welcome

    Could you define, what you mean by session and session identifiers?
    And what are your goals, what do you want to achieve?
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Oct 2012
    Posts
    5
    Quote Originally Posted by Irithori View Post
    Hi and welcome

    Could you define, what you mean by session and session identifiers?
    And what are your goals, what do you want to achieve?
    Hi thanks for reply.

    Not that I have a goal, I am interested in following.

    I know in Linux when a user (say user Bob) logs in a session is created. (I assume this session also has some identifier?).

    Now I am curious, if there is another user (say Alice) logged in, or another session running, can Alice learn which in which session Bob is running? (or alternatively learn the ID of the session where Bob is running?).

    Thank you.

  4. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,356
    Yes, Alice can see
    - who is logged in
    - how often
    - and which (pseudo) terminal (ttyX or pts/X) this user has

    Try this:
    Code:
    w
    You must always face the curtain with a bow.

  5. #5
    Just Joined!
    Join Date
    Oct 2012
    Posts
    5
    Quote Originally Posted by Irithori View Post
    Yes, Alice can see
    - who is logged in
    - how often
    - and which (pseudo) terminal (ttyX or pts/X) this user has

    Try this:
    Code:
    w
    Hi irithori. thanks for your reply, although your code was not visible (corrected: w was the only command apparently ).

    THis is what I mean with session and session ID (I copied it from net):

    "Every process group is in a unique session. (When the process is created, it becomes a member of the session of its parent.) By convention, the session ID of a session equals the process ID of the first member of the session, called the session leader. A process finds the ID of its session using the system call getsid().

    Every session may have a controlling tty, that then also is called the controlling tty of each of its member processes. A file descriptor for the controlling tty is obtained by opening /dev/tty. (And when that fails, there was no controlling tty.) Given a file descriptor for the controlling tty, one may obtain the SID using tcgetsid(fd).

    A session is often set up by a login process. The terminal on which one is logged in then becomes the controlling tty of the session. All processes that are descendants of the login process will in general be members of the session"

    So, now my question is, can Alice (a different user from Bob; assume they are both logged in, but as I mentioned they have different accounts), learn the session ID (as declared above) of Bob??

    thanks!

  6. #6
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,356
    You can get the session id with the systemcall getsid().
    getsid() takes the ProcessID of a running process and returns the Session ID.
    This works even for processes not owned by your user, but I believe this could be restricted.

    You can test this with c code, but php works as well.
    Choose any pid from
    Code:
    ps awux
    and insert it here
    Code:
    php -r 'echo posix_getsid(PIDNUMBER) ;'
    You must always face the curtain with a bow.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •