[SE] ½Ã½ºÅÛ ºÎÆà ½Ã°¢¹× ½Ã°£ ¾Ë¾Æº¸±â - ÀÛ¼ºÀÚ : ±èÄ¥ºÀ - ÀÛ¼ºÀÏ : 2002.11.09 - ºÐ ·ù : ½Ã½ºÅÛ°ü¸®(SE) - ¼ö ÁØ : Ãʺ¸ - ³» ¿ë : ½Ã½ºÅÛ ºÎÆà ½Ã°¢(½ÃÁ¡)°ú ½Ã°£À» ¾Ë¾Æº¸´Â ¹æ¹ý - Å°¿öµå : uptime, last, /proc/uptime, /proc/stat, perl, PHP *ÁÖ) ÀÌ ¹®¼­¿¡ ´ëÇÑ ÃֽŠ³»¿ëÀº ¾Æ·¡ URL¿¡¼­ È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù. http://www.linuxchannel.net/docs/sys-uptime.txt [¹æ¹ý1] uptime ¸í·É¾î °¡Àå °£´ÜÇÑ ¹æ¹ýÀÔ´Ï´Ù. # uptime 9:01pm up 2:12, 1 user, load average: 0.00, 0.00, 0.00 # ÇöÀç Á¦ ½Ã½ºÅÛÀº ºÎÆÃÈÄ 2½Ã°£ 12ºÐ Áö³µ±º¿ä.. À§ÀÇ ¿ÀÈÄ 9½Ã 01ºÐºÎÅÍ ¿ªÀ¸·Î °Å½½·¯ ¿Ã¶ó°¡¸é ºÎÆà ½Ã°¢À» ¾Ë ¼ö ÀÖ°ÚÁÒ.... (°è»êÇÏÁö ¸¶¼¼¿ä. T.T) [¹æ¹ý2] last ¸í·É¾î # last | grep boot | head -n 1 reboot system boot 2.4.19-R2 Sat Nov 9 18:50 (02:12) # Á¦ÀÏ ¸¶Áö¸·ÀÇ (02:12) °ªÀÌ ½Ã½ºÅÛ uptime ÀÔ´Ï´Ù. Áï 2½Ã°£ 12ºÐ Áö³µ´Ù´Â ÀǹÌÀÔ´Ï´Ù. ±×¸®°í 'Sat Nov 9 18:50'Àº ½Ã½ºÅÛ boot time ÀÔ´Ï´Ù. [¹æ¹ý3] /proc/uptime ÀÌ¿ë # cat /proc/uptime 7979.84 7961.31 # ù¹ø° °ªÀº ½Ã½ºÅÛÀÌ ºÎÆÃÈÄ ÇöÀç ½Ã°¢±îÁöÀÇ ºÎÆà ½Ã°£À» ÃÊ´ÜÀ§·Î Ç¥½ÃÇÑ sytem uptime °ªÀÔ´Ï´Ù. µÎ¹ø° °ªÀº 'idle uptime' ÀÔ´Ï´Ù. (reference : /usr/src/linux/fs/proc/proc_misc.c) À§ÀÇ 7979 Ãʸ¦ °è»êÇÏ´Ï ½Ã½ºÅÛÀÌ ºÎÆõÈÁö ¾à 2½Ã°£ 13ºÐÀ̵Ǿú±º¿ä. (uptime ¸í·É¾î·Î È®ÀÎÇÏ¸é °ÅÀÇ °°Àº °ªÀÓ) ±×·³ Á»´õ Á¤È®ÇÏ°Ô ºÎÆà ½Ã°¢À» °è»êÇØ º¾½Ã´Ù. ºÎÆÃÈÄ ±¸µ¿ ½Ã°£ÀÌ 7979ÃÊÀ̹ǷΠÇöÀç UNIX timestamp °ª¿¡¼­ 7979Ãʸ¦ »©¸é ºÎÆýÃÁ¡ÀÇ Unix timestamp °ªÀÌ °è»êµÇÁÒ.. ÀÌ °ªÀ» perlÀÇ gmdate()À̳ª PHPÀÇ data() ÇÔ¼ö¸¦ ÀÌ¿ëÇÏ¸é ½±°Ô ºÎÆýÃÁ¡ÀÇ ½Ã°¢À» ¾Ë ¼ö ÀÖ½À´Ï´Ù(C´Â »ý·«). -- uptime.pl ------------------------------------------------------- #!/usr/bin/perl # # open(UPTIME, '/proc/uptime') or die "Can't open /proc/uptime\n"; while() { @uptime = $_; ## to array } close(UPTIME); $btime = time() - int $uptime[0]; $btime = gmtime($btime + (3600*9)); ## GMT+9 print "boot time : $btime\n"; exit 0; ------------------------------------------------------------------- (½ÇÇà °á°ú) # perl uptime.pl boot time : Sat Nov 9 18:49:55 2002 # -- uptime.php ------------------------------------------------------ ------------------------------------------------------------------- <ÆÁ> ½Ç½Ã°£(1ÃÊ°£°Ý)À¸·Î uptime º¸±â # watch -n 1 cat /proc/uptime Á¾·á´Â 'Ctrl + C' <Âü°í> PHP sysinfo(http://ftp.linuxchannel.net/devel/sysinfo.tar) ÃÖ±Ù ¹öÀü¿¡´Â boot timeÀ» Ãß°¡µÇ¾ú½À´Ï´Ù. [¹æ¹ý4] /proc/stat ÀÌ¿ë # cat /proc/stat cpu 1221 0 639 767372 cpu0 1221 0 639 767372 page 36710 5580 swap 1 0 intr 785185 769232 9 0 0 0 1 3 0 0 7363 8173 0 356 0 0 48 disk_io: (8,0):(3697,2449,73190,1248,11048) ctxt 177800 btime 1036835394 processes 753 # 8¹ø° Ç׸ñÀÇ btime °ª(1036835394)ÀÌ ¹Ù·Î ºÎÆýÃÀÇ UNIX timestamp °ªÀÔ´Ï´Ù. ÀÌ °ªÀº [¹æ¹ý3]¿¡¼­ °è»êÇÑ $btime °ª°ú °°½À´Ï´Ù(¿ÀÂ÷1ÃÊ). ¹Ù²Ù¾î ¸»Çϸé ÇöÀç UNIX timestamp °ª¿¡¼­ ÀÌ btime °ªÀ» »©¸é ½Ã½ºÅÛ uptime °ªÀÌ ³ª¿É´Ï´Ù. ÀÌ uptime °ªÀº [¹æ¹ý3]¿¡¼­ ¾òÀº $uptime[0] °ª°ú °°½À´Ï´Ù. À̹ø¿¡´Â ÀÌ btime °ªÀ» ¾ò¾î¼­ boot timeÀ» Ãâ·ÂÇÏ°í uptime °ªÀ» °è»êÇÏ¿© Àбâ ÆíÇÏ°Ô Ãâ·ÂÇØ º¾½Ã´Ù. -- uptime2.pl ------------------------------------------------------- #!/usr/bin/perl # # reference : http://www.blackplasma.net/scripts/load # open(STAT, '/proc/stat') or "Can't open /proc/stat\n"; $i = 0; while() { $stat[$i] = $_; $i++; } close(STAT); $stat[7] =~ s/[^\d]+//g; ## change boot time(UNIX timestamp) $btime = gmtime($stat[7] + (3600*9)); $term = time() - $stat[7]; $uptime = &runtime($term); print "boot time\t: $btime\n"; print "system uptime\t: $uptime\n"; sub runtime { my($term) = @_; $days = int($term / 86400); $secs = int($term % 86400); $hours = int($secs / 3600); $secs = int($secs % 3600); $mins = int($secs / 60); $secs = int($secs % 60); $days = $days ? "${days}days" : ''; $hours = $hours ? " ${hours}hours" : ''; $mins = $mins ? " ${mins}minutes " : ''; $secs .= 'seconds'; return "$days$hours$mins$secs"; } exit 0 ------------------------------------------------------------------- (Çé... perlÀº ¿ª½Ã ¾î·Æ±º¿ä... T.T) (½ÇÇà °á°ú) # perl uptime2.pl boot time : Sat Nov 9 18:49:54 2002 system uptime : 2hours 25minutes 29seconds # -- uptime2.php ------------------------------------------------------ system uptime\t: $uptime
_EOF_; function runtime($term, $lang='kr') { $l[kr] = $l[ko] = array('ÃÊ','ºÐ','½Ã°£','ÀÏ','´Þ'); $l[en] = array('seconds','minutes','hours','days','mon'); $days = (int)($term / 86400); $secs = (int)($term % 86400); $hours = (int)($secs / 3600); $secs = (int)($secs % 3600); $mins = (int)($secs / 60); $secs = (int)($secs % 60); $days = $days ? $days.$l[$lang][3] : ''; $hours = $hours ? " $hours".$l[$lang][2] : ''; $mins = $mins ? " $mins".$l[$lang][1].' ' : ''; $secs .= $l[$lang][0]; return "$days$hours$mins$secs"; } ?> ------------------------------------------------------------------- [¹æ¹ý5] ±× ¿Ü¿¡ ºÎÆýà »ý¼º/°»½ÅµÇ´Â ·Î±× ÆÄÀÏÀÇ È®ÀÎ # ls -l --full-time /var/log/dmesg -rw-r--r-- 1 root root 6867 Sat Nov 09 18:50:17 2002 /var/log/dmesg # EOF