Sponsored Content
Top Forums Programming I have no clue what's the point - fcntl() ? Post 302075946 by jim mcnamara on Wednesday 7th of June 2006 05:38:46 PM
Old 06-07-2006
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

fcntl(filedescriptor, F_SETLK, struct *flock ) three (3) arguments are required to make fcntl work for locking.

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.
 

7 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Fibre connection Point to Point SUN

Anyone know of a guide or instructions for Solaris I got to configure a SBUS HBA to talk to a tape robot. I have done this on a switch but not point to point. just going HBA >>>>> TAPE Fibre simple two nodes Kie (6 Replies)
Discussion started by: kie
6 Replies

2. Solaris

Filesystem filling up and no clue as to why!

df shows that the filesystem is filling up and the usage is 94%. However when I actually traverse to the directory I du shows only about 10% of the space occupied! Below is the output of df and du: >>>df -kh /cbmdata/00 470M 393M 29M 94% /cbmdata/00 >>>/cbmdata/00>... (3 Replies)
Discussion started by: zombiezparadize
3 Replies

3. Programming

fcntl works in linux but not in mac os x

Hi, Unless I am missing some serious differences in Mac and linux in terms of C programming, I dont know why this would happen. Please take a look at the following piece of code fragment: bool add_input_to_db(Cons *new_data) { // Set the attributes of the lock struct flock fl =... (3 Replies)
Discussion started by: newhere
3 Replies

4. Programming

fcntl on socket

I have very simple client - server setup, where client connects, exchanges some messages with the server and then closes socket and exits. Everythink works OK, except when I am trying to change socket to be non-blocking AND the shell happens to be plain old Bourne. It runs no problem under ksh or... (3 Replies)
Discussion started by: migurus
3 Replies

5. Shell Programming and Scripting

File Locking with fcntl on Darwin Mac OSX

Hello I have a Perl script that works on non-darwin Mac OS X environments and I think I have narrowed down the issue to a file locking problem. In other linux environments, the flock struct is defined differently. I have adjusted this via the reference for Mac OS X fcntl(2) man page. The... (4 Replies)
Discussion started by: flagman5
4 Replies

6. Shell Programming and Scripting

How to perform a hexdump using dd from start point to end point?

hi, I would like to ask or is it possible to dump a hex using dd from starting point to end point just like the "xxd -s 512 -l 512 <bin file>" I know the redirect hexdump -C but i can't figure it out the combination options of dd. Hope someone can share their knowledge.. Thanks in... (3 Replies)
Discussion started by: jao_madn
3 Replies

7. Linux

Block with fcntl

Good evening, friends I'm learning with a book: Programming Linux by Kurt Wall (Prentice Hall) The code below could run in two windows (./lockit /tmp/foo in both for example). There is not problem with the read block (first byte) but when one, apply the write block while in the other is... (1 Reply)
Discussion started by: joe_cosmo
1 Replies
VOP_ADVLOCK(9)						   BSD Kernel Developer's Manual					    VOP_ADVLOCK(9)

NAME
VOP_ADVLOCK -- advisory record locking SYNOPSIS
#include <sys/param.h> #include <sys/vnode.h> #include <sys/fcntl.h> #include <sys/lockf.h> int VOP_ADVLOCK(struct vnode *vp, caddr_t id, int op, struct flock *fl, int flags); DESCRIPTION
The arguments are: vp The vnode being manipulated. id The id token which is changing the lock. op The operation to perform (see fcntl(2)). fl Description of the lock. flags One of more of the following: F_RDLCK Shared or read lock. F_UNLCK Unlock. F_WRLCK Exclusive or write lock. F_WAIT Wait until lock is granted. F_FLOCK Use flock(2) semantics for lock. F_POSIX Use POSIX semantics for lock. This entry point manipulates advisory record locks on the file. Most file systems delegate the work for this call to lf_advlock(). RETURN VALUES
Zero is returned on success, otherwise an error is returned. SEE ALSO
fcntl(2), flock(2), vnode(9) AUTHORS
This manual page was written by Doug Rabson. BSD
June 30, 1999 BSD
All times are GMT -4. The time now is 04:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy