Program sleep pocka pozadovanou dobu a ukonci se. V Linuxu casto pouzivam tento program pri psani skriptu. Ve Windows XP vsak nic podobneho neni. Co by kdo taky cekal od 8 let stareho operacniho systemu (XP je z 25.10.2001)? Jak je to s Windows Vista nevim – nepouzivam.
V Linuxu je syntaxe nasledujici:
sleep 3
pocka 3s
I kdyz ve Windows XP nic podobneho neni, lze si pomoci jinak – programem PING. Kazdeho asi napadne, co ma ping a sleep spolecneho. Odpoved je jednoducha, jestlize se ping spusti se spravnymi parametry, funguje stejne jako sleep. Popis vsech parametru je na strankach Microsoftu.
ping 127.0.0.1 -n 3 -w 1000> nul
pocka 3s
-w doba, po kterou bude ping cekat na odpoved. Zadava se v ms.
-n pocet pozadavku na odpoved. Jelikoz ma ping na localhost (127.0.0.1) prakticky nulovou odezvou, poslouzi jako parametr pro "uspani".
> nul zahodit (nevypisovat) vypisy
Nejjednodussi je vytvorit program, ktery bude vyuzivat funkci sleep. V C by se to dalo napsat nejak podobne:
12345678910111213141516171819202122232425 <font color="#0000ff"><strong>#include <font color="#008000"><stdio.h></font></strong></font><font color="#0000ff"><strong>#include <font color="#008000"><stdlib.h></font></strong></font><font color="#0000ff"><strong>#include <font color="#008000"><Windows.h></font> <font color="#444444"> /* sleep() */</font></strong></font><strong>int</strong> <font color="#2040a0">main</font><font color="#4444ff">(</font><strong>int</strong> <font color="#2040a0">argc</font>, <strong>char</strong> <font color="#4444ff">*</font><font color="#2040a0">argv</font><font color="#4444ff">[</font><font color="#4444ff">]</font><font color="#4444ff">)</font><font color="#4444ff"><strong>{</strong></font><strong>int</strong> <font color="#2040a0">cekat</font><font color="#4444ff">;</font><strong>if</strong> <font color="#4444ff">(</font><font color="#2040a0">argv</font><font color="#4444ff">[</font><font color="#ff0000">1</font><font color="#4444ff">]</font> <font color="#4444ff">=</font><font color="#4444ff">=</font> <font color="#2040a0">NULL</font><font color="#4444ff">)</font><font color="#4444ff"><strong>{</strong></font><font color="#2040a0">printf</font><font color="#4444ff">(</font><font color="#008000">"Jako parametr uvedte cas v sekundach!<font color="#77dd77">\n</font>"</font><font color="#4444ff">)</font><font color="#4444ff">;</font><font color="#4444ff"><strong>}</strong></font><strong>else</strong><font color="#4444ff"><strong>{</strong></font><strong>while</strong> <font color="#4444ff">(</font><font color="#4444ff">(</font><font color="#2040a0">cekat</font> <font color="#4444ff">=</font> <font color="#2040a0">atoi</font><font color="#4444ff">(</font><font color="#2040a0">argv</font><font color="#4444ff">[</font><font color="#ff0000">1</font><font color="#4444ff">]</font><font color="#4444ff">)</font><font color="#4444ff">)</font> <font color="#4444ff">=</font><font color="#4444ff">=</font> <font color="#ff0000">0</font><font color="#4444ff">)</font><font color="#4444ff">;</font><font color="#444444">/* retezec z argv[1] se prevede na cislo */</font><font color="#2040a0">cekat</font> <font color="#4444ff">=</font> <font color="#4444ff">(</font><font color="#2040a0">cekat</font> <font color="#4444ff">*</font> <font color="#ff0000">1000</font><font color="#4444ff">)</font><font color="#4444ff">;</font><font color="#444444">/* funkci sleep se musi zadavat cas v [ms] => * 1000 */</font><font color="#2040a0">sleep</font><font color="#4444ff">(</font><font color="#2040a0">cekat</font><font color="#4444ff">)</font><font color="#4444ff">;</font><font color="#4444ff"><strong>}</strong></font><strong>return</strong> <font color="#ff0000">0</font><font color="#4444ff">;</font><font color="#4444ff"><strong>}</strong></font>
Pokud to nekdo chcete pouzit, tady je 32bit exe. Jestlize ma nekdo 64bit, nebo si to chce nejak upravit, tak tady je projekt v Dev-C++.
Program je dobre nakopirovat do C:\Windows, nebo do jine slozky, ktera je uvedena v promene PATH.