We Bring the Powere of UNIX Linux to Windows -
Click Here To Try For Free

Recent Articles

SCO Bumbles Along
I now, I know: don't kick a man when he's down. Poor SCO doesn't have much time left on this earth, and here I am complaining about their stuff.. oh well, I'm a horrible person and that's just the way it is...

Is There Always A Better Way?
I happened upon a recent Linux-Watch article about Dell's Dynamic Kernel Module Support. I actually downloaded Dell's PDF paper but the LW article is an excellent overview, as is Linux Journal's article on...

Quest & PassGo Team Up On Unix Identity...
Quest Software and PassGo Technologies have entered into an OEM agreement to globally distribute two products for managing and auditing privileged access...

SCO Goes Bankrupt
No great surprise... Dear SCO Customers and Partners, This afternoon we took the extraordinary step of filing for Chapter 11 protection in U.S. Bankruptcy Court to protect assets for our creditors and stockholders and...

Linux And Non-compete Agreements?
There seems to be a lot of discussion about whether Project Indiana at openSolairs is a Linux clone or not. The Project Indiana website states: "Project Indiana is a is a new project to create an OpenSolaris binary...

How Do I Change My PS1 Command Prompt In Bash?
I have read about 15 chapters of your book (Teach Yourself UNIX in 24 Hours) so far. We are using vi. On the PS1 command, how do I see what is in it so I can add to it and not change what is already there? We are...

Bug In Shell Script Using Awk To Read /etc/passwd?
In your book Wicked Cool Shell Scripts, on p. 115, Script #40 Reporting Disk Hogs, on the 8th line the second part of the line reads: awk -F: '$2 > 99 {print $1} ') I am very new to shell scripting, so I am probably just...


11.20.07


Who Locked That File?

By A.P. Lawrence

I can't even imagine how many times I've heard someone complain about a locked file.

Sometimes it's simple - the call goes out "Who has record 758 open?" or something like that, and sure enough, Bill forgot he was working on that, closes it out and all is well. But other times it is not simple, and a system admin has to track down who is doing what.

Note that in this post we're talking about real locking - not a volume that can't be ejected (Mac speak) or a file system that can't be unmounted (the rest of us). For that, just use "lsof" to find out what process is stopping you.

I had a customer call today with the locking problem: "How can we tell if a user has a lock on a file in our application?". I immediately thought of "lsof", because the man page says it should display locking information. It does so on several Linux systems I tested, but does not show that on my Mac.

For testing purposes, we'll need something that locks a file. This very simple C program does that. Note that there is no error checking at all here; it just assumes success on everything. Be sure to "touch mylockedfile" before using this.


We Bring the Powere of UNIX Linux to Windows -
Click Here To Try For Free

All that does is apply a lock to a few bytes of "mylocked" file. It sits and waits for you to press enter, and then teminates. Locks are removed upon process termination, so pressing enter ends everything cleanly.

If you called that program "makelock.c", then "make makelock" should compile it and "touch mylockedfile;./makelock" should set it running. You should see this:



Continue reading this article.


About the Author:
A.P. Lawrence provides SCO Unix and Linux consulting services http://www.pcunix.com

About UnixProNews
UnixProNews is a collection of news and commentary designed to keep you in step with the ever evolving landscape of Unix environments. News and Advice for Unix Professionals

UnixProNews is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com ITCertificationNews.com


-- UnixProNews is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2007 iEntry, Inc. All Rights Reserved Privacy Policy Legal

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article


News and Advice for Unix Professionals UnixProNews News Archives About Us Feedback UnixProNews Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact