![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How do i change to super user then revert back to ordinary user ,using shell script? | wrapster | Shell Programming and Scripting | 3 | 06-04-2008 08:11 AM |
| Displaying current user process | felixwhoals | Shell Programming and Scripting | 14 | 12-16-2007 07:00 PM |
| How to check the status of the processes running for the current user? | ravind27 | UNIX for Dummies Questions & Answers | 1 | 07-05-2007 04:10 AM |
| To look for occurrences of the current user | bobby36 | Shell Programming and Scripting | 1 | 04-12-2007 12:19 AM |
| how to find password for current user in unix box | balireddy_77 | Shell Programming and Scripting | 1 | 01-30-2007 03:42 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
|||||
|
Sign on to your system and type the command "env". I believe that you will find both variables set. At least I see them both on redhat.
And type "man environ". I see them as the first two ducumented environment settings. What do you see? Maybe your login scripts unset both environment variables? But looking at this thread and your other thread involving mtime, the more probable answer is that you are having some difficulties with programs that you write. |
|
||||
|
I don't think one can get password of a logged user but there are many a ways by which one can know the user who has logged in.
Perderabo has already defined multiple ways and all that I want to add is standard C library routine to find a username / terminal associated with the current process: #include <stdio.h> char *cuserid(char *s); char *ctermid(char *s); See man pages for more details. |
|
|||||
|
Read paragraph 3 of my first post for comments on getuid(). Hmmm, I see that I said to use getpwnam(). Actually, since we have the uid, we should use getpwuid().
ctermid() is a silly little function that always returns the string "/dev/tty". I will never understand why people write functions to return a constant. cuserid() was dropped from posix in 1990. It is still available on many systems, but I recommend that it not be used for new code. It first tries the technique I mentioned in the second paragraph of my first post. If that fails, it then uses the getuid() technique that I mentioned in my third paragraph. No information is available to the caller about which technique worked. And it never tries the technique mentioned in my first paragraph which posix seems to promote as the preferred method. Also there is getlogin() which automates looking up the controlling terminal in utmp. I have the uneasy feeling that there are more functions that automate some conbination of the 3 techniques that I mentioned. It's dangerous to be sure of a negative, but I'm rather sure that there isn't a 4th technique lurking around. |
![]() |
| Bookmarks |
| Tags |
| mtime |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|