![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ssh with shared mount point | devjxh | SUN Solaris | 4 | 11-30-2007 04:54 AM |
| Please point the error | skyineyes | Shell Programming and Scripting | 1 | 07-05-2007 05:26 AM |
| how to get rid of decimal point? | cin2000 | Shell Programming and Scripting | 2 | 12-27-2005 08:26 AM |
| mount point | colesy | UNIX for Dummies Questions & Answers | 1 | 01-06-2004 03:03 AM |
| Fibre connection Point to Point SUN | kie | UNIX for Advanced & Expert Users | 6 | 05-20-2003 08:20 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
I have no clue what's the point - fcntl() ?
hi, I need to know how to lock a file. I used the following code, but after executing the program the file 'write.txt' remined empty, and I have no idea why.Maybe I'm not using the corresponding syntax for blocking a file. But I deleted then the blocking part and the problem persisted.
see to code: ...... f=open("read.txt",O_RDONLY); fcntl(f,F_SETLK); read(f,buffer,sizeof(buffer)); g=open("write.txt",O_WRONLY); write(g,buffer,sizeof(buffer)); close(g); fcntl(f,F_UNLCK); close(f); ....... then I tried to replace open with fopen (so I use FILE *g of course, and fprintf()) but still nothing was in that file(write.txt).So I have no clue. If you got sometime pls say somethin'. I need to do this as soon as I can. You are welcomed to say somethin' smart 10x Last edited by atticus; 06-07-2006 at 02:40 PM. |
| Forum Sponsor | ||
|
|
|
|||
|
I think you mean lock a file.
Try creating a file with stuff in it to start with Code:
echo "now my file has stuff in it" > write.txt Note - a lot of unix kernels do not support mandatory locking. This means that anybody who breaks the rules (like your code is doing) will still be able to stomp on somebody else's file. Regardless of fcntl. In other words, locking depends on each C module playing by the rules. |
|
|||
| Google The UNIX and Linux Forums |