LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-27-2005, 06:51 AM   #1
prital
LQ Newbie
 
Registered: Dec 2004
Posts: 24

Rep: Reputation: 15
sleep() call


Hello,
I've run the following user application in the linux environment:

int main()
{
FILE * fp = fopen ("/log_file" , "w");
int n=0;

while(n++ < 20)
{
fprintf(fp, "%s", "OK");
sleep(1);
}
fclose(fp);
return 0;
}

The problem is that the file /log_file is created, but is empty.
If I remove the sleep() call, the file /log_file gets the "OK" strings.

How the sleep() call may interfere with the fprintf() call?
Any idea to solve this?
Thank you very much.
 
Old 06-27-2005, 06:55 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Code:
fflush(fp);
 
Old 06-27-2005, 07:04 AM   #3
prital
LQ Newbie
 
Registered: Dec 2004
Posts: 24

Original Poster
Rep: Reputation: 15
fflush works.
Thank you.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching for Server (BOOTP/DHCP) <sleep> <sleep> .. .. Eileen Linux - Networking 12 10-21-2005 01:14 AM
I am trying implement sleep in read system call problem sbharsha Programming 1 09-18-2005 11:48 PM
What do you call your remote control? I call mine... RHLinuxGUY General 19 10-18-2004 06:23 AM
sleep TroelsSmit Linux - Newbie 10 05-22-2004 01:17 AM
to sleep or not hejduk Linux - General 3 03-28-2002 03:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration