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 09-14-2006, 08:45 PM   #31
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115

xhi: Pipes do store data, it is just extremely volatile. If you don't read from your pipes but keep writing to them, they will overflow
 
Old 09-14-2006, 09:10 PM   #32
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Original Poster
Rep: Reputation: 30
tuxdev do you know how to get around my issue?
 
Old 09-14-2006, 09:13 PM   #33
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
tuxdev, thanks for the info. that is good to know.

Centinul, how long are these log lines ?
 
Old 09-14-2006, 09:15 PM   #34
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Original Poster
Rep: Reputation: 30
they're length changes.. it's probably anywhere from 180 - 250 characters. I really thought this method was going to work. I got really excited when my regular expressions were done and working. As soon as I tried to run it with the while loop around it, it starts working really funny like I described. Very discouraging. I'm beginning to wonder if what I want to do is possible.
 
Old 09-14-2006, 09:24 PM   #35
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
hmm, yeh i dont know for sure. is it possible that getline reads the data from the pipe before your logger is done writing to the pipe? you know like jumping in and reading a half line before the whole line is written.

you should test the return value of getline and see if it is 0 or -1, -1 is error or eof, 0 is just no chars read. so that might help some and you could also throw a few prints in there and see how much it actually reading on that second read.

otherwise it looks like it should work (disregarding concurrency issues between the logger, the pipe, and the reader), id see if you are getting a -1 or 0 first..
 
Old 09-15-2006, 09:06 AM   #36
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
I wonder how "tail" does this, cause I can run "tail -f" to monitor my syslog realtime.
 
Old 09-16-2006, 10:00 AM   #37
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Original Poster
Rep: Reputation: 30
ok I ran the program while printing out the getline code that is returned. It never returned a 0 or a -1. It always seem to return the length of the line (which in this case was either 210 or 211 characters). It still is acting in that weird fashion. Also I tend to notice that the pipe sometimes likes to die.

I think ultimately I think I need a way to get the information from the file when it changes. I'm not sure if pipes are the answer. It seems like they are to volatile and not reliable. With that said is there anyway I can accomplish reading data from a file continuously in real time?

There HAS to be a way to do this reliably and effectively. I can't really come up with any other ideas. The only other one I have is some sort of buffer mechanism where 5 - 10 lines at a time can be read into a buffer. I wouldn't know how to implement it though because I wouldn't know where the last line I used stopped.

::EDIT:: I figured out the problem. I was passing an offset by reference when doing my string parsing. I forgot to reset it to zero when I ended the string parsing. It all seems to work now.

Last edited by Centinul; 09-16-2006 at 10:46 AM.
 
Old 09-18-2006, 02:49 PM   #38
soggycornflake
Member
 
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
Regarding pipes, a pipe is a kernel construct of a fixed size (the size is hardcoded into the kernel, default is 4K (or maybe 1 page, not sure)). Note sure what is meant by "volatile", no data is lost, once the pipe is full, a writing process will block until someone reads from the other end (or in non-blocking mode, returns with -1 and errno==EAGAIN). Of course, it's up to the writing process to buffer any unwritten data.
 
Old 09-19-2006, 04:13 PM   #39
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
Quote:
Originally Posted by soggycornflake
Regarding pipes, a pipe is a kernel construct of a fixed size (the size is hardcoded into the kernel, default is 4K (or maybe 1 page, not sure)). Note sure what is meant by "volatile", no data is lost, once the pipe is full, a writing process will block until someone reads from the other end (or in non-blocking mode, returns with -1 and errno==EAGAIN). Of course, it's up to the writing process to buffer any unwritten data.
wait, so it wont overflow then. it will either block until read from or fail.

that seems to be opposite of what tuxdev mentioned earlier. dammit, now i may have to do research.. unless we can come to an agreement of who is right here.
 
Old 09-19-2006, 05:13 PM   #40
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
Actually, we both be in agreement, just he explained more. Methinks a pipe is volatile because it be only in memory, and in normal case, quite active. Me essentially wanted ta say it be a Bad Thing for a pipe to reach its limit.
 
Old 09-19-2006, 07:17 PM   #41
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Someone tell me why this approach, which I thought was obvious, doesn't fly.
Read the file from beginning to end.
Call ftell(), to find out where in the file you are.
Save the result in one of:
a.) disk file
b.) chunk of shared memory
c.) memory queue
d.) anywhere that has a persistant lifetime
Close file and quit.
For all subsequent iterations:
Open the file.
Read the saved position.
fseek() to the required position.
Read to end-of-file
Get new position from ftell()
Save position, close file, quit.

This seems to make use of facilites created specifically for this purpose.
What am I missing?

--- rod.
 
  


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
Force Use of Additional Swap File Moogey Linux - Software 2 08-17-2006 06:43 PM
pulling Active Directory information jsheffie Red Hat 2 08-16-2006 10:49 AM
how to change some text of a certain line of a text file with bash and *nix scripting alred Programming 6 07-10-2006 11:55 AM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
SH SCRIPT +pulling information from a text file chrisfirestar Linux - General 1 01-30-2004 07:14 AM

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

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