Expectations in the C component?

Is there a wait statement in the c component? for example, wait 0.5 seconds before continuing with the process?

thanks!

+3
source share
4 answers

POSIX has

usleep(500);

and

nanosleep(...);

read the manual for usleep(3)and nanosleep(2). EDIT : nanosleepnow there may be a way, usleepeven outdated POSIX.2008in accordance with its man page!

+7
source

To summarize and fix a minor issue in a post by Johannes Weiss (non-German keyboard, sorry):

POSIX- usleep(), . , , :

#include <unistd.h>
usleep(500000); /* Five hundred thousand microseconds is half a second. */

POSIX ( man- Gentoo Linux POSIX.1-2001), nanosleep(), , . :

#include <time.h>
struct timespec t;
t.tv_sec = 0;
t.tv_nsec = 500000000; /* Five hundred million nanoseconds is half a second. */
nanosleep(&t, NULL); /* Ignore remainder. */

nanosleep() "rem" , - . NULL . , ( ) , , , - .

+7

Windows API

Sleep(500);

MSDN. .

+3
source

sleep is also available in POSIX, the difference is that the argument specifies the number of Seconds instead of the milliseconds during which the process should sleep.

0
source

Source: https://habr.com/ru/post/1703104/


All Articles