Article View: fr.comp.lang.c
Article #15203Re: notion de temps
From: Pierre Maurette
Date: Wed, 05 Oct 2005 06:58
Date: Wed, 05 Oct 2005 06:58
41 lines
2388 bytes
2388 bytes
gil, le 05/10/2005, a �crit : > Bonjour � vous, > > je cherche � faire un tout petit programme (en c biens�r) du genre de sleep > (unix) Si vous cherchez un tout petit sleep, voyez peut-�tre du cot� des string (dans string.h) > qui me permettre d'attendre un certain temps en seconde avant d'ex�cuter > d'autres commandes dans un script batch. > > #!/sh > sleep 3 > > Comment avoir une notion de temps en C ? La seule chose portable que je vois, c'est clock() de <time.h>: #include <time.h> /* ..... */ int attente_sec = 3; clock_t fin = clock() + (CLOCKS_PER_SEC * attente_sec ); while(clock() < fin); ou float fattente_sec = 0.5; clock_t fin = clock() + (clock_t)((float)CLOCKS_PER_SEC * fattente_sec); while(clock() < fin); Si vous avez quelque chose � faire dans la boucle while(), c'est mieux. �a peut fonctionner, comme �a peut �tre catastrophique selon l'utilisation que vous en faites (attente quasi permanente) et le type de multit�che de votre plateforme. Il vaudrait mieux passer par les fonctions de l'OS s'il est d�termin�, ce qui semble �tre le cas. -- Pierre Maurette
Technical Details
Message-ID:
<mn.2a1a7d5afd420743.31483@laposte.net>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!infeed-2.proxad.net!news16-e.free.fr!not-for-mailReferences:
<dhuute$h61$1@apollon.grec.isp.9tel.net>Show Full Headers
Complete Article Headers
X-Google-Thread: f9822,4e02ca09709eaded
X-Google-Attributes: gidf9822,public
X-Google-Language: FRENCH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!infeed-2.proxad.net!news16-e.free.fr!not-for-mail
Subject: Re: notion de temps
From: "Pierre Maurette" <maurettepierre@wanadoo.fr>
References: <dhuute$h61$1@apollon.grec.isp.9tel.net>
Newsgroups: fr.comp.lang.c
Message-ID: <mn.2a1a7d5afd420743.31483@laposte.net>
X-Newsreader: MesNews/1.04.00.00
Date: Wed, 05 Oct 2005 08:58:02 +0200
MIME-Version: 1.0
X-Face: cmi$3R1_J{[}5K|8d'LDiJ$SsZ*gn,j*PhJ#KVGt+45,E_N9O}GrhhQ>fb&q<&lz=g%PEv' u"m)N|KrBMux?2:E?N7Uw3L#H>L#GwM}<qH-?#_Y$B9]$q1"~iUGtN#HVy?}7.`m&iKF>gY:.`W.qu z`1'W'h-AXPmB]#7~<+@H.<0M`-jBkCWbmkcT_*LBVD3|p1a?h1H;cHq{$-vbeP@Hdcqp5z~lwU7ZK `~
Reply-To: maurettepierre@wanadoo.fr
Content-Type: text/plain; charset="iso-8859-15"; format=flowed
Content-Transfer-Encoding: 8bit
X-Antivirus: avast! (VPS 0540-1, 04/10/2005), Outbound message
X-Antivirus-Status: Clean
Lines: 43
Organization: Guest of ProXad - France
NNTP-Posting-Date: 05 Oct 2005 08:56:19 MEST
NNTP-Posting-Host: 84.7.241.13
X-Trace: 1128495379 news16-e.free.fr 5290 84.7.241.13:4619
X-Complaints-To: abuse@proxad.net