Visit Our UNIX and Linux User Community


Sleep or Dealy fucntion Issue


 
Thread Tools Search this Thread
Top Forums Programming Sleep or Dealy fucntion Issue
# 1  
Old 07-04-2007
Sleep or Dealy fucntion Issue

I am doing some programming using C on UNIX. The thing is, I have been working in both UNIX and Windows for practicing.

I created a Delay fucntion over Windows using DevC++ as a compiler, when I tried over the console, it worked as I expected, I mean it was creating a delay (of one second for example) between each operation.

When I tried this function over UNIX, it didn't get the same results. I would like to know what is happening. Then, I tried a Sleep function from the <unistd.h> library and it did the same. When I tried to do an operation that will be printed in the same line, the delay used between each operation is acummulated and then everything is done. For example;

Sleep(1); printf("Hi"); Sleep(1); printf("How"); Sleep(1); printf("are"); Sleep(1); printf("you?");

I have to wait four seconds to get all the expression to be printed in the screen, instead of getting each expresion with a one second delay. I hope somebody can help me out. I will aprecciate any help.

Other thing, I have been using the conio.h library of windows to put some color on the console. What can I used on UNIX? Can anybody give a working example?
# 2  
Old 07-04-2007
1. try

Code:
sleep(1);
printf("Hi");
fflush(stdout);
sleep(1);
printf("How");
fflush(stdout);
sleep(1); 
printf("are"); 
fflush(stdout);
sleep(1); 
printf("you?"); 
fflush(stdout);

the problem you describe is caused by stdio doing buffering.

2. look to curses/ncurses to provide terminal independent fancy output else encode VT100 escape sequences yourself.
# 3  
Old 07-04-2007
Ok I am going to try the code you are telling me. It is wear how different works the stdio in Windows so.

Can you help out with the curses.h library? I just want to put some color and maybe some flashing text.. that's all..
# 4  
Old 07-05-2007
They are (a) different operating systems and (b) have different implementations of the C library.

http://www.comptechdoc.org/os/linux/...x_hlvt100.html
# 5  
Old 07-05-2007
I want the details for UNIX. Either KDE 3.5 or KNOPPIX 5.1. By the way, I tried what you told me and it work very good!

How do I use the VT100 ESC Sequences?

Thanks!

Last edited by josejesus3340; 07-05-2007 at 12:31 AM..
# 6  
Old 07-05-2007
Quote:
Originally Posted by josejesus3340
I want the details for UNIX.
That's why we are here.

Quote:
Originally Posted by josejesus3340
Either KDE 3.5 or KNOPPIX 5.1.
Then surely X-Windows would be the route to go.

Quote:
Originally Posted by josejesus3340
How do I use the VT100 ESC Sequences?
Embed them in the character stream you write to the terminal..

Code:
printf("\033[5m");

# 7  
Old 07-05-2007
Let me understand something. If I want to put some color to for example:

printf("\033[5m"); printf("Blue");

printf("\033[5m"); printf("Green");

Is it going to be this way? or everything together?

Previous Thread | Next Thread
Test Your Knowledge in Computers #449
Difficulty: Medium
Linux Mint was originally based on Kubuntu.
True or False?

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sleep while i > 0

Hi, I have a script that runs a process at the beginning and I want to sleep/wait until this process is finished and then continue with the rest of the script. I am trying with this, but it is not working: process=`ps -ef | grep "proc_p01 -c" | grep -v grep | wc -l` if ; do sleep 10 done... (7 Replies)
Discussion started by: apenkov
7 Replies

2. UNIX for Dummies Questions & Answers

ISSUE on SFTP fucntion ,parameter passing!

Hi Everyone!! Hey i created a SFTP function to FTP the file from unix to Linux. I need to FTP the 48 files from unix to linux. IP=$1 Userid=$2 Prikeypath=$3 SrcPath=$4 DstPath=$5 Files=$6 BATCHFILE=sftp.batch.$$ LOGFILE=sftp.log.$$ #Compose batch file & pass as argument to the... (1 Reply)
Discussion started by: bobprabhu
1 Replies

3. Shell Programming and Scripting

Wrapping 'sleep' with my 'resleep' function (Resettable sleep)

This is a very crude attempt in Bash at something that I needed but didn't seem to find in the 'sleep' command. However, I would like to be able to do it without the need for the temp file. Please go easy on me if this is already possible in some other way: How many times have you used the... (5 Replies)
Discussion started by: deckard
5 Replies

4. UNIX for Dummies Questions & Answers

Sleep less than 1 second

Does anyone know a way to sleep less than 1 second? Sometimes when I write scripts that iterates a loop many times it would be nice to slow things down, but sometimes 1 second is too much. (9 Replies)
Discussion started by: bjorno
9 Replies

5. UNIX for Dummies Questions & Answers

system sleep

Dear All , I installed new Linux Red Hat 9 system and it is working fine . but while i keep it for certain time ideal ( i mean ndo not wrok on system itself ) it goes to mode like sleep mode ,,, but while it is in sleep mode i can not ping it or telnet !! i discovered it while i was telnet... (8 Replies)
Discussion started by: tamemi
8 Replies

6. Shell Programming and Scripting

Sleep under one second

If I want a script to sleep for less than a second, would I use a decimal? In other words, if I wanted my script to sleep for 1/4 of a second, would I say, SLEEP .25 ?? (5 Replies)
Discussion started by: Scoogie
5 Replies

7. UNIX for Dummies Questions & Answers

sleep

what is the purpose of the sleep command? (5 Replies)
Discussion started by: Anna
5 Replies

Featured Tech Videos