
time_nanosleep() 함수의 첫 번째 인자로 전달되는 struct timespec 타입의 변수의 첫 번째 필드인 tv_sec는 초 단위 시간을 나타냅니다.
tv_sec는 초 단위 시간을 나타내는 필드이며, nanoseconds 단위 시간을 나타내는 필드는 tv_nsec입니다.
tv_nsec은 nanoseconds 단위 시간을 나타내는 필드이며, 0에서 999999999 사이의 값이 가능합니다.
예를 들어, 1초는 1000000000 nanoseconds로 표현할 수 있습니다.
struct timespec 타입의 변수를 다음과 같이 선언할 수 있습니다.
#hostingforum.kr
c
struct timespec sleep_time;
sleep_time.tv_sec = 1; // 1초
sleep_time.tv_nsec = 0; // nanoseconds 단위 시간은 0으로 초기화
이러한 구조를 사용하여 time_nanosleep() 함수를 호출할 수 있습니다.
#hostingforum.kr
c
int ret = time_nanosleep(&sleep_time, NULL);
2025-08-15 15:47