File read/ write operation


 
Thread Tools Search this Thread
Operating Systems Linux File read/ write operation
# 8  
Old 05-27-2010
Thanks for your reply. So, let me see what I can do, will get back again.

---------- Post updated at 02:12 PM ---------- Previous update was at 02:09 PM ----------

So, do you have any idea about Ajax? Any suggestion? I need to send a variable basically from server to client. Ajax can read .xml and .txt files. But I think it is not working the way I want. As, I want to read the data by Ajax each time the server writes to the file, instead when it has completed the process of writing. To add here, I REPLACE my text not add the data, so at a time my text file just have one value out of 1 to 100.
Moreover, although I am replacing my text and data could be read only once whole values are written, but the strange part here is that my Ajax could still read all the values one by one.
For this I tried putting the sleep(1); in between data write to file, and here my progress bar incremented after each 1 second. However this is not desirable as this process initiated after the whole file write not at the moment it was written

Last edited by xs2punit; 05-27-2010 at 04:17 PM..
# 9  
Old 05-27-2010
Even if you do manage to transmit this variable to the AJAX script somehow it's going to be a very awkward solution involving lots of retries, handfuls to dozens to hundreds more HTML retrievals than really necessary, etc. This should be solved on the server end, not the client. Instead of a rube goldberg system to check if an EOF was the real EOF, just don't EOF unless you mean it when sending the file to the client!

Advisory locking, as already said, is the way to do this. The server-side script that writes the file should always keep the very last section of the file locked. When it finishes writing another block, lock it, unlock the one before, write more, lock, unlock, etc. Once it's finally done,unlock the file completely.

The server-side script that reads the file should do much the same: always lock the section before it reads it. If the writer program doesn't have data ready for it, it'll be made to wait until the writer unlocks it. So lock a section, read it, unlock it, lock the next section, read it, unlock, repeat until EOF.

The relevant function call is flock.
# 10  
Old 05-27-2010
I do not want to lock anything. That is not the issue. Issue is server doesn't release the file to be read.
# 11  
Old 05-28-2010
Quote:
Originally Posted by xs2punit
I do not want to lock anything.
Clearly. You should, though. Otherwise you're going to hit all the pitfalls we've been telling you about repeatedly, and all you'll be doing by doing it in AJAX instead is building your own slower, buggier, flock-over-http protocol from the ground up.
Quote:
Issue is server doesn't release the file to be read.
Doesn't release the file? What error do you get when you try to retrieve it -- does it think the file's not present at all, or give 'permission denied', etc. Either is quite odd, most UNIX systems don't do mandatory locking of open files, nor play tricks to hide files until they're complete; what system are you using?

Last edited by Corona688; 05-28-2010 at 02:32 PM..
# 12  
Old 06-01-2010
My issue is not that my data is getting corrupted, my issue is that my data is not written and read the way I want.
My server writes to the file and client reads the file. As ajax at the client could ONLY read the file, there is no point of locking.

Well regarding "file release" thing: I mean that the data is not available while it is getting updates, so it seems that the file is being held until whole process is completed.
ie:
if i write 1,2....100 in text file , intead of the changing values 1,2,3 etc; i get
1,2,..100 at ONCE not one by one ie not at the time when it is UPDATED.

I am using Linux, you are write that Linux doesn't hold/hide the file. So, may be this is not a Linux issue. In case you have knowledge of Ajax, let me know if can discuss this further.

Thanks

hope this makes sense to you.
# 13  
Old 06-02-2010
I have written AJAX-driven systems callign linux scripts, yes.
Quote:
Originally Posted by xs2punit
As ajax at the client could ONLY read the file, there is no point of locking.
We've told you over and over what the locking's for and why you need it for reading a file that something else is appending to.
Quote:
Well regarding "file release" thing: I mean that the data is not available while it is getting updates, so it seems that the file is being held until whole process is completed.
Again, linux doesn't hold the file. Locking of that sort is opt-in and you're not opting. The behavior you describe seems more and more strange...

By file do you mean a real, genuine, unparsed, honest-to-god file? Or do you actually mean your AJAX is reading output fetched from a server-side script? They act very differently, and the latter would act like what you're saying, and wouldn't need locking like you're saying. The web browser would just wait for its output. If you're reading script output, and it's arriving all at once, it's probably line-buffering. Flush the output on the server side whenever you really want the script to send. Or, just write a newline, which should flush it too.

Last edited by Corona688; 06-03-2010 at 12:04 AM..
# 14  
Old 06-03-2010
well you can refer to this File upload progress bar - Stack Overflow
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read and write in the file

Hello Guys, How all are doing? I have an issue in Unix and want help from all of you I have a file in UNIX which it read by line by line , If at the end of line '0' is written the it should fetch that line into another file and change '0' to '1' and If at the end of line '1' is written then it... (10 Replies)
Discussion started by: adisky123
10 Replies

2. Shell Programming and Scripting

File Read and Write

I have got a file in following format: AAAAAAA BBBBBBBB CCCCCCC DDDDDDD I am trying to read this file and out put it in following format: AAAAAAA,BBBBBBB,CCCCCCC,DDDDDD Preferred method is shell or Perl. Any help appreciated. (11 Replies)
Discussion started by: Araoki
11 Replies

3. Shell Programming and Scripting

Grab data between 2 keywords any do an array operation and write the file intact

Hi Unix Gurus, I need to grep for a block that is between a start and end keyword and then in between I need to find and replace a keyword. for eg: I need to search between Test = 000; and Test = 000; and find K9 and replace with M9 INPUT FILE Define { Replace = K9; Test =... (6 Replies)
Discussion started by: naveen@
6 Replies

4. Shell Programming and Scripting

Transferring file write operation to another host

I have a process running on two hosts in Active/Standby mode. Process running on active machine is handling the traffic while process running on Standby machine is sitting idle. We have a debugging mechanism in which logs are generated on local machine. When logging is enabled then process running... (1 Reply)
Discussion started by: akhilonnet
1 Replies

5. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

6. Solaris

monitoring multipath IO for read and write operation

Hi Folks, I would like to monitor multipath IO on solaris for write and read operations. Does "sar -d" include multipath IO information along with other block devices ? Thanks, Faizan. (0 Replies)
Discussion started by: sifaizan
0 Replies

7. UNIX for Dummies Questions & Answers

Write/read to file descriptors

Is it possible to write to file descriptor 0 and read from 1 or 2? How could this be implemented? (3 Replies)
Discussion started by: machshev
3 Replies

8. UNIX for Dummies Questions & Answers

Simultaneous file read operation

Hi All, I need information on file handling in UNIX enviornment. If in UNIX enviornment I have two process.. P1 P2 Both accessing the same file simultaneosuly(read operation).. Suppose P1 opened the file in read mode first and started reading the file.. Then P2 opens the same file in... (5 Replies)
Discussion started by: chibob
5 Replies

9. Shell Programming and Scripting

read and write from a file

I have tried to show the file name whose size is greater than 200 byte in current directory. Please help me. ls -l | tr -s " " " " | cut -f 5,9 -d " " >out.txt #set -a x `cat out.txt` i=0 `cat out.txt` | while do read x echo $x #re=200 j=0 if }" < "200" ] then echo $j j=`expr $j... (2 Replies)
Discussion started by: rinku
2 Replies

10. IP Networking

how do you get to know if the write operation was succesful.

how do you get to know if the write operation for writing to a socket was succesful was succesful. (3 Replies)
Discussion started by: arjunjag
3 Replies
Login or Register to Ask a Question