萬盛學電腦網

 萬盛學電腦網 >> Linux教程 >> linuxc獲取系統關機時間的代碼

linuxc獲取系統關機時間的代碼

  源碼如下:

  #include

  #include

  #include

  #include

  int main()

  {

  struct utmp *u ;

  FILE *fp = fopen("shutdown_note","w+");

  utmpname("/var/log/wtmp");

  while((u = getutent()))

  {

  if(strncmp(u->ut_user,"shutdown",8) == 0)

  fprintf(fp," %s time: %s", u->ut_user, ctime((time_t *)(&u->ut_tv.tv_sec)));

  }

  endutent();

  return 0;

copyright © 萬盛學電腦網 all rights reserved