who命令

#include 
#include 
#include 
#include 
#include 
#include 

#define SHOWHOST

int main()
{
    struct utmp current_record;
    int     utmpfd;
    int     reclen = sizeof(current_record);
    
    if( ( utmpfd = open(UTMP_FILE,O_RDONLY ) ) == -1){
        perror(UTMP_FILE);
        exit(1);
    }
    
    while( read ( utmpfd,¤t_record,reclen ) == reclen)
        show_info(¤t_record);
    close(utmpfd);
    return 0;
}
show_info( struct utmp * utbufp)
{
    //printf("%u \n",utbufp ->ut_type);
    if ( utbufp ->ut_type != USER_PROCESS)
        return;
    printf("% -4.4s", utbufp->ut_name);
    printf(" ");
    printf(" % -8.8s" , utbufp ->ut_line);
    printf(" ");
    //printf(" % 50d", utbufp ->ut_time);
    showtime( utbufp->ut_time );
    printf(" ");
    #ifdef SHOWHOST
    printf( "( %s)", utbufp->ut_host);
    #endif
    printf( "\n") ;
}
showtime(long timeval)
{
    char * cp;
    cp = ctime(&timeval);
    printf("%12.12s",cp+4);
}

你可能感兴趣的:(who命令)