473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

why it does not sleep?

Hi all.

I have the following code and the 1000 numbers has stored before calling
fifo(),in fifo,why it does not sleep for 1 sec ?it just stop there,but
if i delete sleep(1) ,the number will successfully printed on screen.

Thanks a lot guys!

================================================== ========

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int n[1000];//copy of 1000 numbers
//============================================

//fcfs,fifo:first in first out
void fifo(void){
int reqinter[1000];
for (int i=0;i<1000;i++){
printf("%d ",n[i]);
sleep(1);
}
}

//sst:shortest seek time
void sst(void){

}

//elev:elevator
void elev(void){

}

//cscan:circular scan
void cscan(void){

}

//============================================

//============================================
int main (int argc,char* argv[]) {
//=========get input=================
for(int i=0;i<1000;i++){
scanf("%d",&n[i]);

}

//==========begin to request==========

fifo();
sst();
elev();
cscan();

//====================================
return 0;
}

================================================== ==============
Jul 22 '05 #1
2 5168

"JosephWu" <wu*******@hotmail.com> wrote in message
news:Xn***********************@202.180.64.19...
Hi all.

I have the following code and the 1000 numbers has stored before calling
fifo(),in fifo,why it does not sleep for 1 sec ?it just stop there,but
if i delete sleep(1) ,the number will successfully printed on screen.

You probably need to flush the standard output to make sure that the output
occurs immediately. See below.
Thanks a lot guys!

================================================== ========

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int n[1000];//copy of 1000 numbers
//============================================

//fcfs,fifo:first in first out
void fifo(void){
int reqinter[1000];
for (int i=0;i<1000;i++){
printf("%d ",n[i]);
Add this

fflush(stdout);
sleep(1);
}
}


john
Jul 22 '05 #2
Hi,

"JosephWu" <wu*******@hotmail.com> wrote in message
news:Xn***********************@202.180.64.19...
Hi all.

I have the following code and the 1000 numbers has stored before calling
fifo(),in fifo,why it does not sleep for 1 sec ?it just stop there,but
if i delete sleep(1) ,the number will successfully printed on screen.

Thanks a lot guys!

================================================== ========

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int n[1000];//copy of 1000 numbers
//============================================

//fcfs,fifo:first in first out
void fifo(void){
int reqinter[1000];
for (int i=0;i<1000;i++){
printf("%d ",n[i]);
sleep(1);
}
}
Check the return value of sleep

while( sleep(1) );
Though I am not sure what happens with a one second sleep.

sleep can be interrupted on most unix systems by an interrupt and will then
return even if the time hasn't expired!
It will return the seconds that is has to go

Regards, Ron AF Greve.

//sst:shortest seek time
void sst(void){

}

//elev:elevator
void elev(void){

}

//cscan:circular scan
void cscan(void){

}

//============================================

//============================================
int main (int argc,char* argv[]) {
//=========get input=================
for(int i=0;i<1000;i++){
scanf("%d",&n[i]);

}

//==========begin to request==========

fifo();
sst();
elev();
cscan();

//====================================
return 0;
}

================================================== ==============

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: zapazap | last post by:
Dear Snake Charming Gurus, (Was: http://mail.python.org/pipermail/python-list/2004-January/204454.html) First, a thank you to Tim Golden, Thomas Heller, and Mark Hammond for your earlier help...
7
by: Colin Brown | last post by:
Python 2.3.3 Under Windows NT: Negative Int or Real -> sleeps for a long time Under Linux: Returns IOError: Invalid argument I consider both of these unfriendly results and expected the...
0
by: Mathias Mamsch | last post by:
Hi all, I got a problem with writing a python extension module which launches a bunch of C threads (currently under windows). The module launches a complete speech recognition engine in a new...
5
by: Dave | last post by:
For the life of me, I thought there was a sleep() function in the Standard Library (or something similarly named), but I can't find it. Is it non-existent or, if not, what header is it in? ...
5
by: bughunter | last post by:
Hi, Consider this code: ---- Monitor.Pulse(oLock); Monitor.Exit(oLock); ---- If a thread was waiting on oLock then will the current thread
0
by: skip | last post by:
I just noticed the announcement of Shed Skin 0.0.16 on Freshmeat with this (partial) change announcement: Changes: frozenset was added. time.sleep now works on Win32. Given Python's highly...
17
by: christophe.chazeau | last post by:
Hi, I have a problem with a really simple chunk of code which should work but does obviously does not. This chunk of code is just a POC aimed at finding a bug in a larger project in which the...
4
by: Steven De Smet | last post by:
Hello, This is my first post. I searched on the internet for answers but I was unable to solve my problem. So I hope that you guy's can help me with my VB.NET problem I tried to create a...
13
by: Charles Zhang | last post by:
Sleep() function Sleep at lease 1 millisecond, there is a way to make a thread to sleep less than a millisecond? One way I know of is using performance counter which is not really sleep ( loop and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.