# Command to display SID and login name



## mvladimriov (Dec 4, 2009)

There are two system calls getsid(2) and getlogin(2) that return session identifier and login name associated to current session, but it seems that there is no user command to show these values.  I expect id(1) command to be able to show SID and login name, but it can not (at least in 6.4-STABLE release I'm currently using).

It should be quite easy to extend id(1) command to be able to print these values.

Are there any reason why these values could not be displayed via user commands?


----------



## SirDice (Dec 4, 2009)

Err.. `% grep $ID /etc/passwd`?


----------



## mvladimriov (Dec 4, 2009)

Just clarify.  Value returned by getlogin(2) system call may differ from value of USER environment variable.  It also can differ from user name corresponding to current UID or EUID.

For example, "su -l" will change UID and EUID and $USER, but login name associated to current session as well as SID will be unchanged.


----------



## SirDice (Dec 4, 2009)

mvladimriov said:
			
		

> For example, "su -l" will change UID and EUID and $USER, but login name associated to current session as well as SID will be unchanged.


su -l spawns a new process with the new UID. The parent process keeps the 'old' UID.


```
USER      PID  PPID  PGID   SID JOBC STAT  TT       TIME COMMAND
dice    15162 15161 15162 15162    0 Is     1    0:00.08 -tcsh (tcsh)
root    15185 15162 15185 15162    1 I      1    0:00.04 su -
root    15186 15185 15186 15162    1 S      1    0:00.09 -su (csh)
root    15249 15186 15249 15162    1 R+     1    0:00.01 ps -axj
```


----------



## Wiedmann (Dec 4, 2009)

> getlogin(2)




```
/usr/bin/logname
```



> getsid(2)


maby something like:

```
ps -o sid -p $$ | tail -1
```


----------



## mvladimriov (Dec 4, 2009)

Wiedmann said:
			
		

> ps -o sid -p $$ | tail -1



Good!


```
ps -o logname -p $$ | tail -1
```

Will show login name.  So it is possible, but slightly weird.


----------

