timer_settime(2) - wariua/manpages-ko GitHub Wiki
timer_settime, timer_gettime - POSIX ํ๋ก์ธ์ค๋ณ ํ์ด๋จธ ์ฅ์ /ํด์ ๋ฐ ์ํ ๊ฐ์ ธ์ค๊ธฐ
#include <time.h>
int timer_settime(timer_t timerid, int flags,
const struct itimerspec *new_value,
struct itimerspec *old_value);
int timer_gettime(timer_t timerid, struct itimerspec *curr_value);
-lrt
๋ก ๋งํฌ.
glibc ๊ธฐ๋ฅ ํ์ธ ๋งคํฌ๋ก ์๊ฑด (feature_test_macros(7) ์ฐธ๊ณ ):
-
timer_settime()
,timer_gettime()
: _POSIX_C_SOURCE >= 199309L
timer_settime()
์ timerid
๊ฐ ๋ํ๋ด๋ ํ์ด๋จธ๋ฅผ ์ฅ์ ํ๊ฑฐ๋ ํด์ ํ๋ค. new_value
์ธ์๋ ํ์ด๋จธ์ ์ ์ต์ด ๊ฐ๊ณผ ์ ๊ฐ๊ฒฉ์ ๋ํ๋ด๋ itimerspec
๊ตฌ์กฐ์ฒด์ ๋ํ ํฌ์ธํฐ์ด๋ค. itimerspec
๊ตฌ์กฐ์ฒด๋ ๋ค์๊ณผ ๊ฐ์ด ์ ์๋์ด ์๋ค.
struct timespec {
time_t tv_sec; /* ์ด */
long tv_nsec; /* ๋๋
ธ์ด */
};
struct itimerspec {
struct timespec it_interval; /* ํ์ด๋จธ ๊ฐ๊ฒฉ */
struct timespec it_value; /* ์ต์ด ๋ง๋ฃ */
};
itimerspec
๊ตฌ์กฐ์ฒด์ ํ์ ๊ตฌ์กฐ ๊ฐ๊ฐ์ timespec
๊ตฌ์กฐ์ฒด์ฌ์ ์๊ฐ ๊ฐ์ ์ด์ ๋๋
ธ์ด๋ก ์ง์ ํ ์ ์๋ค. timer_create(2)๋ก ํ์ด๋จธ๋ฅผ ๋ง๋ค ๋ ์ง์ ํ ํด๋ญ์ ๋ฐ๋ผ ์ด ์๊ฐ ๊ฐ๋ค์ ์ธก์ ํ๋ค.
new_value->it_value
๊ฐ 0 ์๋ ๊ฐ์ด๋ฉด (์ฆ ํ ํ์ ํ๋๋ผ๋ 0์ด ์๋๋ฉด) timer_settime()
์ ๊ทธ ์๊ฐ์ ์ต์ด ๋ง๋ฃ๋๋๋ก ์ค์ ํ์ฌ ํ์ด๋จธ๋ฅผ ์ฅ์ (์์)ํ๋ค. (ํ์ด๋จธ๊ฐ ์ด๋ฏธ ์ฅ์ ๋์ด ์์ผ๋ฉด ์ด์ ์ค์ ์ ๋ฎ์ด ์ด๋ค.) new_value->it_value
๊ฐ 0 ๊ฐ์ด๋ฉด (์ฆ ๋ ํ์ ํ๋ ๋ชจ๋ 0์ด๋ฉด) ํ์ด๋จธ๋ฅผ ํด์ ํ๋ค.
new_value->it_interval
ํ๋๋ ์ด์ ๋๋
ธ์ด๋ก ํ์ด๋จธ์ ์ฃผ๊ธฐ๋ฅผ ๋ํ๋ธ๋ค. ์ด ํ๋๊ฐ 0์ด ์๋๋ฉด ์ฅ์ ๋ ํ์ด๋จธ๊ฐ ๋ง๋ฃ๋ ๋๋ง๋ค new_value->it_interval
์ ์ง์ ํ ๊ฐ์ผ๋ก ํ์ด๋จธ๋ฅผ ์ฌ์ฅ์ ํ๋ค. new_value->it_interval
์ด 0 ๊ฐ์ด๋ฉด it_value
๋ก ์ง์ ํ ์๊ฐ์ ํ ๋ฒ๋ง ํ์ด๋จธ๊ฐ ๋ง๋ฃ๋๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก new_value->it_value
๋ก ์ง์ ํ๋ ์ต์ด ๋ง๋ฃ ์๊ฐ์ ํธ์ถ ์์ ์ ํ์ด๋จธ ํด๋ญ์ ํ์ฌ ์๊ฐ์ ๊ธฐ์ค์ผ๋ก ์๋์ ์ผ๋ก ํด์ํ๋ค. flags
์ TIMER_ABSTIME
์ ์ง์ ํด์ ๋ฐ๊ฟ ์ ์๋๋ฐ, ๊ทธ๋ ๊ฒ ํ๋ฉด new_value->it_value
๋ฅผ ํ์ด๋จธ ํด๋ญ์์ ์ธก์ ํ ์ ๋๊ฐ์ผ๋ก ํด์ํ๋ค. ์ฆ ํด๋ญ ๊ฐ์ด new_value->it_value
๋ก ์ง์ ํ ๊ฐ์ ๋๋ฌํ ๋ ํ์ด๋จธ๊ฐ ๋ง๋ฃ๋๋ค. ์ง์ ํ ์ ๋ ์๊ฐ์ด ์ด๋ฏธ ์ง๋ฌ์ผ๋ฉด ํ์ด๋จธ๊ฐ ์ฆ์ ๋ฐํ๋๋ฉฐ ์ด๊ณผ ํ์(timer_getoverrun(2) ์ฐธ๊ณ )๊ฐ ๊ทธ์ ๋ง๊ฒ ์ค์ ๋๋ค.
CLOCK_REALTIME
ํด๋ญ ๊ธฐ๋ฐ์ ์ ๋๊ฐ ํ์ด๋จธ๊ฐ ์ฅ์ ๋์ด ์๋ ๋์ ๊ทธ ํด๋ญ์ ๊ฐ์ ์กฐ์ ํ๋ ๊ฒฝ์ฐ์๋ ํ์ด๋จธ ๋ง๋ฃ๊ฐ ์ ์ ํ ์กฐ์ ๋๋ค. CLOCK_REALTIME
ํด๋ญ ๊ธฐ๋ฐ์ ์๋๊ฐ ํ์ด๋จธ์๋ ํด๋ญ ์กฐ์ ์ด ์ํฅ์ ์ฃผ์ง ์๋๋ค.
old_value
๊ฐ NULL์ด ์๋๋ฉด ๊ทธ ๋ฒํผ๋ฅผ ์ด์ฉํด ํ์ด๋จธ์ ์ด์ ๊ฐ๊ฒฉ(old_value->it_interval
)๊ณผ ํ์ด๋จธ๊ฐ ๋ค์์ผ๋ก ๋ง๋ฃ๋ ๋๊น์ง ๋จ์๋ ์๊ฐ(old_value->it_value
)์ ๋ฐํํ๋ค.
timer_gettime()
์ timerid
๋ก ์ง์ ํ ํ์ด๋จธ์ ๋ํด ๋ค์ ๋ง๋ฃ๊น์ง์ ์๊ฐ๊ณผ ๊ฐ๊ฒฉ์ curr_value
๊ฐ ๊ฐ๋ฆฌํค๋ ๋ฒํผ๋ก ๋ฐํํ๋ค. ๋ค์ ํ์ด๋จธ ๋ง๋ฃ๊น์ง ๋จ์ ์๊ฐ์ curr_value->it_value
๋ก ๋ฐํํ๋๋ฐ, ํ์ด๋จธ๋ฅผ ์ฅ์ ํ ๋ TIMER_ABSTIME
ํ๋๊ทธ๋ฅผ ์ผ๋์ง์ ์๊ด์์ด ํญ์ ์๋์ ์ธ ๊ฐ์ด๋ค. curr_value->it_value
๋ก ๋ฐํ๋ ๊ฐ์ด 0์ด๋ฉด ํ์ด๋จธ๊ฐ ํ์ฌ ํด์ ๋์ด ์๋ ๊ฒ์ด๋ค. ํ์ด๋จธ ๊ฐ๊ฒฉ์ curr_value->it_interval
๋ก ๋ฐํํ๋ค. curr_value->it_interval
๋ก ๋ฐํํ ๊ฐ์ด 0์ด๋ฉด "๋จ๋ฐ์ฑ" ํ์ด๋จธ์ธ ๊ฒ์ด๋ค.
์ฑ๊ณต ์ timer_settime()
๋ฐ timer_gettime()
์ 0์ ๋ฐํํ๋ค. ์ค๋ฅ ์ -1์ ๋ฐํํ๋ฉฐ ์ค๋ฅ๋ฅผ ๋ํ๋ด๋๋ก errno
๋ฅผ ์ค์ ํ๋ค.
์ด ํจ์๋ค์ ๋ค์ ์ค๋ฅ๋ก ์คํจํ ์ ์๋ค.
EFAULT
-
new_value
๋old_value
,curr_value
๊ฐ ์ ํจํ ํฌ์ธํฐ๊ฐ ์๋๋ค. EINVAL
-
timerid
๊ฐ ์ ํจํ์ง ์๋ค.
timer_settime()
์ ๋ค์ ์ค๋ฅ๋ก ์คํจํ ์๋ ์๋ค.
EINVAL
-
new_value.it_value
๊ฐ ์์์ด๋ค. ๋๋new_value.it_value.tv_nsec
์ด ์์์ด๊ฑฐ๋ 999,999,999๋ณด๋ค ํฌ๋ค.
๋ฆฌ๋ ์ค 2.6๋ถํฐ ์ด ์์คํ ํธ์ถ๋ค์ด ์ฌ์ฉ ๊ฐ๋ฅํ๋ค.
POSIX.1-2001, POSIX.1-2008.
timer_create(2) ์ฐธ๊ณ .
timer_create(2), timer_getoverrun(2), time(7)
2017-09-15