반응형
[2022/04/06] Add title image
[2022/03/20] Add usleep()
[2022/03/12] Start
소나무 기운 , 전자제품 개발/생산
sleep() usleep() for linux, Sleep() for windows
Sleep() for windows
#include <stdio.h>
#include <windows.h>
Sleep(1000); // 1000 ms
sleep() for linux
#include <stdio.h>
#include <time.h>
#include <unistd.h>
int main()
{
char buf[250];
printf("start\n");
time_t begin;
time(&begin);
sleep(1);
time_t end;
time(&end);
printf("end %0f Sec\n", difftime(end, begin));
}
usleep() for linux
#include <stdio.h>
#include <time.h>
#include <unistd.h>
int main()
{
char buf[250];
struct timespec start={0,0}, end={0,0};
clock_gettime(CLOCK_MONOTONIC, &start);
usleep(700000); // 700mS
clock_gettime(CLOCK_MONOTONIC, &end);
printf("%.2f seconds\n",((double)end.tv_sec + 1.0e-9*end.tv_nsec) - ((double)start.tv_sec + 1.0e-9*start.tv_nsec));
}
마무리
참고문헌
틀린 부분이나 질문은 댓글 달아주세요.
즐거운 하루 보내세요. 감사합니다.
반응형
'Raspberry Pi (Linux, ubuntu)' 카테고리의 다른 글
CoolTerm, Install Serial HEX terminal in linux. (0) | 2022.03.29 |
---|---|
Raspberry Pi SD Card backup & recover in the windows. (0) | 2022.03.28 |
How to Install x11vnc server on Ubuntu 20.04 (0) | 2022.03.08 |
UDP socket , Broadcast send (0) | 2022.03.08 |
linux, ubuntu shutdown command (0) | 2022.03.08 |
댓글