Created
November 1, 2012 05:17
-
-
Save gcmurphy/3991998 to your computer and use it in GitHub Desktop.
who
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <memory.h> | |
#include <utmpx.h> | |
int main(void) | |
{ | |
struct timeval last_hour; | |
struct timeval last_login; | |
struct utmpx *entry = NULL; | |
gettimeofday(&last_hour, NULL); | |
last_hour.tv_sec = last_hour.tv_sec - 3600; | |
while ((entry = getutxent()) != NULL) { | |
printf("User %s is using %s. The pid is %d\n", | |
entry->ut_user, entry->ut_line, entry->ut_pid); | |
if (0 == timercmp(&(entry->ut_tv), &(last_hour), <)){ | |
printf("%s logged in within the last hour\n", entry->ut_user); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment