Skip to content

Instantly share code, notes, and snippets.

@ranjib
Created June 28, 2013 20:10
Show Gist options
  • Save ranjib/5887708 to your computer and use it in GitHub Desktop.
Save ranjib/5887708 to your computer and use it in GitHub Desktop.
And you think system administrators are grumpy ? :-)
#include <sys/sysinfo.h>
#include <stdio.h>
int seconds2days(int seconds){
return seconds/(60*60*24);
}
int days2year(int days){
return days/365;
}
int main(argc){
struct sysinfo info;
int uptime, age, exitstatus=0;
sysinfo(&info);
uptime = seconds2days((int) info.uptime);
uptime = 427;
age = days2year(uptime);
if (uptime < 1){
printf("Im a new born!\n");
}
else if((uptime % 365) == 0 )
{
printf("Happy '%d' birth day to you!\n", age);
exitstatus=1;
}
else
{
printf("Im '%d' year , '%d' day old!\n", age, uptime%365);
}
return exitstatus;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment