Visit Our UNIX and Linux User Community


System Resources?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users System Resources?
# 1  
Old 11-12-2003
System Resources?

I am running a C program on a SCO box. There are multiple users on using the system resources. My problem is when using fprintfs in the program. I am writing to a log every thing I read in from a file after doing some formatting. I write out to the log with the fprintfs in groupings like 10 fprintfs in a row and then further on down in the program 75 more fprintfs all in a row. When it writes the 75 fprinfts it looses the valid data about midway through the writes to the log. I noticed when I comment out the 1st grouping of 10 fprintfs the second group of 75 fprintfs still lose valid data during the writes, but not till further down in sequence. Although it is not a direct 1 to 1 relationship the more fprintfs I comment out in the beginning of the sequence the further it gets to end of the fprinfts to the point that it will finish writing to the log all the valid data.

Could limited memory resources cause this problem by reallocating memory, if the available memory is less then when the program was compiled, or would it error out during execution?
# 2  
Old 12-07-2003
You need to use fflush(stderr) after every fprintf you use, this way all the data' s will get printed correctly, just try out, if you still face any problems reply with more details.

Cheers Smilie
# 3  
Old 12-08-2003
From the fflush man page:

fflush() causes any unwritten data for that stream to be written to the file, and the st_ctime and st_mtime fields of the underlying file are marked for update.

In the past, I've typically masked each fflush by using a local subroutine that takes the same input as fprintf, but also does the flush - keeps the code readable if fprintf(s) abound.

Cheers,

Keith
# 4  
Old 12-08-2003
I just do a setvbuf(stdout, NULL, _IONBF, 0) if I don't want buffering.

But I'm not sure that buffering per se is the issue here. The "lose valid data" does not strike me as the way to describe a delay in seeing the data. It may be that the OP has a bug that resulted in re-using the area already assigned as a buffer. When the buffer fills, the other data is trashed. If this is the case, turning off buffering may hide the symptom, but it does not fix the root problem.

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Ubuntu

Xorg is taking System Resources.

Hi All, I am facing System Speed problem.i saw in top command Xorg process was taking most of the time 20% of CPU and Memory.How to make it normal. Currently i am using AMD Athlon 64 HT technology processor(Socket 939) 512 DDR1 RAM Nvidia 5200 GeForce 128 MB Graphic card. i need help in... (2 Replies)
Discussion started by: arvindk.monu
2 Replies

2. UNIX for Advanced & Expert Users

Looking for utility to monitor system resources

Hi Community, I'm looking for a linux based utility for monitoring following system resources 1. Memory 2. CPU Usage I know there are plenty freewares which poll the data and print in form of html pages. For eg. MRTG, Novel's Linux Monitoring tools etc. But my requirement is deviated a... (1 Reply)
Discussion started by: anilgurwara
1 Replies

3. UNIX for Advanced & Expert Users

VI hogging system resources???

Hello all. I was on my pc last night when I noticed that my hard drive light was on and when I typed in "uptime" I recieved some crazy load averages. load average: 3.30, 3.07, 2.95. Anyway I type in "top" to see what processes are being the resource hogs and im surprised as hell to see that one... (2 Replies)
Discussion started by: ThePreacher
2 Replies

Featured Tech Videos