Can someone tell me the difference between these commands namely?
ctermid(), ttyname(), cuserid(), getlogin()
Printable View
Can someone tell me the difference between these commands namely?
ctermid(), ttyname(), cuserid(), getlogin()
The ctermid() function generates a string that, when used as a pathname, refers to the current controlling terminal for the current process.
ttyname() - This returns name of a terminal.
cuserid() - This get character login name of the user
getlogin() - This returns a pointer to a string containing the user name associated by the login activity with the controlling terminal of the current process
Interesting to learn!!!! The associated header files for each are given below:
ctermid() - stdio.h
ttyname() - unistd.h
cuserid() - stdio.h
getlogin() - unistd.h
The syntax for cuserid() is
#include <stdio.h>
char *cuserid(char *t);
The function cuserid() gives the user id associated with the process.
The interesting part is in the return values of this function cuserid() namely
If t is not a null pointer but if the associated login id or name could not be found then *t is placed with '\0' which denotes a null byte.
If t is a null pointer and if the associated login id or name could not be found then return value from this function is a null pointer
If t is a null pointer and if the associated login id or name can be found then return value from this function is the address of the storage area which has the corresponding login id or the username of the process.