프로그램을 돌리는 중에 매시간 마다 시간을 찍게 하려면...

miso의 이미지

프로그램을 실행 시켜서....
한시간 마다 혹은 몇 분마다... 시간을 알려고 하는데요...
시간 차는 어떻게 구하나요...
이곳 QnA를 보고 ctime이라는 함수를 쓰면... 시간을 구한 수 있는 것 같은데....
시간 차는 어떻게 구하나요?
너무 황당한 질문인가요?
제가 잘 몰라서...

choissi의 이미지

알람 셋팅을 하면... sigalrm을 받아서

시그널 핸들러에서 특정 시간마다 하고 싶은
작업을 하면 됩니다

울랄라~ 호기심 천국~!!
http://www.ezdoum.com

miso의 이미지

시스템에서 설정하는 것가요?
만약에 소스에서 하는 것이하면.. sigalram이라는 함수 사용예 좀 알려 주시면 안될까요?
제가 하려는 작업은....
제가 서버를 만들었는데요...
서버에 접속한 사용자 수를 10분 간격으로 알고 싶어서 그런데요..
그러면.. 내가 2시 30분에 사용자 수를 찍고 2시 40 분에 또 사용자 수를 찍고.... 이런 식으로요...
그렇게 하려면... 10분이라는 차이를 알아야 하잖아요...
time_t time1, time2 이렇게 변수를 선언해서...
time1에서 이전 시간을 저장하고... time2에서 현재 시간을 저장해서
time2 - time1 = 10분이라는 계산이 가능한지....
이것이 궁금한데요...

*^^*

송지석의 이미지

가능합니다.

저는 ctime을 사용하지는 않았고요..

timeval 이었나 하는 구조체를 사용했는데..

gettimeofday 라는 함수가 있습니다.

이 함수를 사용해서 처음시간을 구한 다음 저장해두고

루프를 돌며 폴 하시면서 gettimeofday로 현재 시간을 구하시고 차이를 구하시면 되겠네요.

GETTIMEOFDAY(2)            Linux Programmer's Manual           GETTIMEOFDAY(2)

NAME
       gettimeofday, settimeofday - get / set time

SYNOPSIS
       #include <sys/time.h>

       int gettimeofday(struct timeval *tv, struct timezone *tz);
       int settimeofday(const struct timeval *tv , const struct timezone *tz);

DESCRIPTION
       The functions gettimeofday and settimeofday can get and set the time as
       well  as a timezone.  The tv argument is a timeval struct, as specified
       in /usr/include/sys/time.h:

       struct timeval {
               long tv_sec;        /* seconds */
               long tv_usec;  /* microseconds */
       };

       and gives the number of seconds and microseconds since the  Epoch  (see
       time(2)).  The tz argument is a timezone :

맨페이지 인용입니다.

지금 회사가 아니라서 자세한 설명이 불가능하네요.. 저는 제가 짠 코드도 보고 짜야 돼서.. ㅡㅡ;;; 회사에 방화벽이 깔려있거든요.

저는 시간차를 구하는 함수를 만들어서 초단위로 계산하게 합니다만..

gettimeofday(현재시간);
if(시간차(초기시간,현재시간)>10초)
{
    초기시간 = 현재시간;
    print("10초\n");
}
이렇게 말이죠.

넵 그럼. 이만.

errai의 이미지

alarm(10);

이라고 해주시면 10초 후에 현재의 프로세스에 SIGALRM 시그널을
전송하게 됩니다.

그리고 간단하게 현재의 사용자를 출력하게 하는 SIGALRM에 대한 핸들러를
만들어 놓으면 잘 동작할 것입니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.