-
Expert Member
Difference in these UNIX commands
Can someone tell me the difference between these commands namely?
ctermid(), ttyname(), cuserid(), getlogin()
-
Contributing Member
Re: Difference in these UNIX commands
The ctermid() function generates a string that, when used as a pathname, refers to the current controlling terminal for the current process.
-
Contributing Member
Re: Difference in these UNIX commands
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
-
Contributing Member
Re: Difference in these UNIX commands
Interesting to learn!!!! The associated header files for each are given below:
ctermid() - stdio.h
ttyname() - unistd.h
cuserid() - stdio.h
getlogin() - unistd.h
-
Contributing Member
Re: Difference in these UNIX commands
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules