LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-29-2011, 09:33 AM   #1
sparsh0mittal
LQ Newbie
 
Registered: Nov 2011
Posts: 23

Rep: Reputation: Disabled
C++ cout output stops after sometime


Hello I am doing simulation, where output is printed on screen. Earlier I was using cerr to print on screen, but later switched to std::cout. The same output is also printed in a log file. But the problem is: after sometime, the output stops printing on the screen; although, the output keeps on printing in the log file. I know that "\n" is required to flush the stream, but even if I use it, there is no output after some time. When exactly output stops is not fixed and changes in different simulations.

Can someone help?
Sparsh
 
Old 11-29-2011, 06:48 PM   #2
selfprogrammed
Member
 
Registered: Jan 2010
Location: Minnesota, USA
Distribution: Slackware 13.37, 14.2, 15.0
Posts: 635

Rep: Reputation: 154Reputation: 154
Several tests, just to determine the cause of the stoppage.
1. Clear the upper bit of output to prevent graphic and special codes that are functions to the terminal emulation.
2. Block ESC sequences to the terminal. These can trigger terminal functions.
3. Test for special codes like CTRL-S, which pauses the terminal display.
4. Disable all output stmts except one, then test. Then do the same with each output line.
Determine if stoppage problem is associated with any particular output stmt.
5. Put in extra output stmts. It does not matter if they cause screen to look like garbage, they only track the last known print line. Test if the stoppage is earlier, and maybe determine where.
6. Before every output stmt, put in a debugging output to the screen that gives a sequence number (to identify the last print), identifies the particular line, and any state that would help. After every output stmt, put in a simple print to the terminal that tests if the output is still working. When the output stops, the last thing on the screen with the highest sequence number should identify which line is the cause, and the state. Large amount of state can be saved to the log file marked using the same sequence number.

Last edited by selfprogrammed; 11-29-2011 at 06:49 PM.
 
1 members found this post helpful.
Old 11-29-2011, 06:59 PM   #3
raconteur
Member
 
Registered: Dec 2007
Location: Slightly left of center
Distribution: slackware
Posts: 276
Blog Entries: 2

Rep: Reputation: 44
Just coverin' the bases here -- have you checked the state of the Scroll Lock key on your keyboard (if it has that key)?

It wasn't clear from your post whether that could be a culprit, but I don't think there is one among us who hasn't been bamboozled by that key at some point.
 
1 members found this post helpful.
Old 11-29-2011, 08:15 PM   #4
sparsh0mittal
LQ Newbie
 
Registered: Nov 2011
Posts: 23

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by raconteur View Post
Just coverin' the bases here -- have you checked the state of the Scroll Lock key on your keyboard (if it has that key)?

It wasn't clear from your post whether that could be a culprit, but I don't think there is one among us who hasn't been bamboozled by that key at some point.
Never heard of that before! My keyboard has that key, but it does not light anything, even if you press it. What can scroll-lock do?
 
Old 11-29-2011, 08:18 PM   #5
sparsh0mittal
LQ Newbie
 
Registered: Nov 2011
Posts: 23

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by selfprogrammed View Post
Several tests, just to determine the cause of the stoppage.
1. Clear the upper bit of output to prevent graphic and special codes that are functions to the terminal emulation.
2. Block ESC sequences to the terminal. These can trigger terminal functions.
3. Test for special codes like CTRL-S, which pauses the terminal display.
4. Disable all output stmts except one, then test. Then do the same with each output line.
Determine if stoppage problem is associated with any particular output stmt.
5. Put in extra output stmts. It does not matter if they cause screen to look like garbage, they only track the last known print line. Test if the stoppage is earlier, and maybe determine where.
Generally, when output is too much, it gets stuck. Moreover, since it is random phenomenon, so test 4 & 5 is ruled out. I think it is one of 1,2,3. Can you explain: upper bit of output? Block ESC sequence? special codes? Thanks for your time and reply.
 
Old 11-30-2011, 03:03 AM   #6
King_DuckZ
Member
 
Registered: Nov 2009
Location: Rome, IT
Distribution: Sabayon
Posts: 61

Rep: Reputation: 2
Just a precision: \n doesn't flush the output, it's just a character like the others. What you need in order to flush is to pass in std::endl, or to call flush() explicitly on the stream.
What std::endl does is nothing more than passing "\n" to the stream and calling flush() right after.

From http://publib.boulder.ibm.com/infoce...y/id00067.htm:
Avoid using endl where the new-line character is required but buffer flushing is not, because endl has a much higher overhead than using the new-line character.

Also, I'm not sure if this applies to c++, but I recall having had a problem with ruby when I was sending a text too long to the output function. The solution then was to pass through a function that called puts() with fixed size parts of the input text. I'm not sure what ruby does internally (probably it's not even using cout), but it could be worth checking.
 
2 members found this post helpful.
Old 11-30-2011, 05:27 PM   #7
selfprogrammed
Member
 
Registered: Jan 2010
Location: Minnesota, USA
Distribution: Slackware 13.37, 14.2, 15.0
Posts: 635

Rep: Reputation: 154Reputation: 154
Those 1 to 5 tests are suggested specifically because it is random and you do not yet know which output statement is triggering the stoppage. The CTRL-S code printed does the same thing as pressing the SCROLL-LOCK on the keyboard, it pauses the output display.

Clear the upper bit.
You do not need to modify text strings, but binary output is suspect.
If you output any char codes directly, just as a test clear the high bit on them.
<< ch ; ---> << (ch & 0x7F) ;

ESC sequence.
They start with an escape char.
If you have code that outputs characters, then test for the escape.
<< f(x) ----> chfx = f(x); if( chfx == 27 ) { << "ESC" ; } else { << chfx ; }

Special codes.
Outputting char outside the ASCII printing glyph range 32..127, may hit a special code.
These codes are interpreted by VT100,VT102 terminals as functions like clear_screen, switch to alternate font, and others. Most displays emulate the VT100, VT102 functions in software and will respond to these codes. Make sure you do not output these by accident. They will
not do anything special in a log file, but they should be visible.

Likely, somewhere you are outputing raw binary, that by accident is triggering a terminal function, like SCROLL-LOCK. These should show up in the log as "^S" or similar characters, or if you display the log using a font with those characters present, they could look like any strange character.
 
1 members found this post helpful.
Old 11-30-2011, 05:59 PM   #8
sparsh0mittal
LQ Newbie
 
Registered: Nov 2011
Posts: 23

Original Poster
Rep: Reputation: Disabled
@selfprogrammed
Thanks. I will try these and let you know.
 
  


Reply

Tags
c++, output



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
Video output stops during installation brokeefe Linux - Desktop 5 05-22-2011 04:03 PM
what is the output of cout or ts (in case of filesystem in QT) << navderm Programming 1 01-06-2009 12:10 PM
C++: cout problem tntcoder Programming 3 08-02-2007 10:13 PM
output to screen stops when booting? Eppo Slackware 2 03-04-2007 02:13 AM
c++ cout not working :( Longinus Programming 10 08-01-2004 07:32 PM

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

All times are GMT -5. The time now is 12:42 AM.

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