Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C implementation of the unix "who" command

Status
Not open for further replies.

jl3574

Programmer
Jun 5, 2003
76
CA
i'm trying to write a C program which shows detail of user who are logged on an Unix server kinda like the "who" command.
i want it to show the user name, terminal line, log in time, and processid
i'm having trouble starting this
maybe someone can help
thx :)
 
To get this task done you have to parse UTMP file where all open terminal gets registered.
In the case of linux for example it is /var/log/wtmp.
And of course it is worth take a look at "who" source,
which is a part of coreutils package.
 
i try to include the utmp.h and utmpx.h files
and create an instance of the umtp struct so i can read it
but somehow it's not working here's my code
plz help.
the compiler says:
"undefined symbol: utmpx
syntax error before or at: obj"
if the struct utmpx is part of the utmpx.h header shouldn't this work?
================================================
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <utmp.h>
#include <utmpx.h>
int main()
{


int fd, i, size;

if((fd=open(&quot;/var/adm/utmpx &quot;,O_RDWR)) == -1){
perror(&quot;file problem &quot;);
exit(1);
}

utmpx obj;
read(fd,obj,sizeof(obj));

return 0;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top