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 04-01-2008, 02:11 AM   #1
return.c
LQ Newbie
 
Registered: Mar 2008
Distribution: Fedora
Posts: 11

Rep: Reputation: 0
blocking system calls - question


I have a following piece of code

printf("creating log file ... ");
result = ee_log.init();
if(result == true)
{
printf("success \n");
}
else if(result == false)
{
perror("error - > Error in opening log file.");
return false;
}

but while running the program, I get "error - > Error in opening log file." printed before "creating log file ... ". Is this something to do with blocking system calls ?

It has to be like this

creating log file ...
error - > Error in opening log file.: Permission denied

But What I am getting in the terminal is

error - > Error in opening log file.: Permission denied
creating log file ...
 
Old 04-01-2008, 02:59 AM   #2
BugZRevengE
Member
 
Registered: Oct 2005
Location: Australia
Distribution: Slackware & Kubuntu & CentOS
Posts: 106

Rep: Reputation: 17
Not really sure, but is perror outputting to stdout or stderr ? it may be related, because I think the printf is to stdout, and perror is to stderr... I am not sure how to change the order, but I think there would be a way. If you want you can redirect one or the other by redirecting 1> /path/stdout.txt 2> /path/stderr.txt

more info, and how to redirect both can be found here:
http://www.cpqlinux.com/redirect.html

hope this helps
 
Old 04-01-2008, 04:50 AM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
It's because stdout is line buffered and stderr is not buffered at all. So the "creating log file..." will be printed when the program terminates. If you add a \n to the "creating log file..." message, the buffer will be flushed.
 
Old 04-01-2008, 11:57 AM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by Guttorm View Post
If you add a \n to the "creating log file..." message, the buffer will be flushed.
If you don’t want the linefeed, you can force a buffer flush with
Code:
fflush(stdout);
 
  


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
how does java calls the system calls which are written in c babu198649 Linux - General 3 12-05-2011 03:40 AM
Looking for List of Blocking System Calls lapin3000 Linux - Software 2 12-06-2007 08:56 AM
how do you use system calls? slinky2004 General 1 12-22-2005 09:39 PM
System calls question alltime Programming 1 11-29-2005 08:31 PM
kernel thread and blocking calls asurya Linux - General 1 09-22-2005 11:15 PM

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

All times are GMT -5. The time now is 07:33 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