How to determine if a File is Open?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to determine if a File is Open?
# 1  
Old 01-31-2002
Question How to determine if a File is Open?

I need to know what the best way, if possible in a perl or shell script, to determine if a file is open by a process, and if it is open for writing.

While I would rather use a perl or shell script, if I have to use C, that would be ok.

Thanks.
# 2  
Old 01-31-2002
According to me this is much more easy in C.

Here is a way to find out :-

You can use fwrite function to write data into file. Before using fwrite function use fcntl and check whether the file is locked by other thread/program.

For more information refer to the man pages of fcntl & fwrite.

Aniruddha
# 3  
Old 02-01-2002
There is a standard program called "fuser" that can tell you who has a file open. And there is a much better freeware program called "lsof" to do the same thing.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to determine if there's a file in directory!

Hi All, I'm just wondering how can i determined if there's a file in directory and put it in a logs? dir="/home/test/" Please advise, Thanks, Use code tags, thanks. (1 Reply)
Discussion started by: nikki1200
1 Replies

2. Shell Programming and Scripting

Determine file age in days?

I am using AIX 6.1 and would like to use a one line command to determine the age of a file in days. I would like to look at a specific file. I would like to use the command to run on a remote server (AIX 6.1) to return the age of a specific file in days. So if the file is 42 days old I would... (2 Replies)
Discussion started by: oldman2
2 Replies

3. Red Hat

cannot set user id: Resource temporarily unavailable (not open file/open process related)

First post, sorry to be a bother but this one has been dogging me. I have a process user (java application server) that trips a resource limit every couple weeks and need help finding what limit we're hitting. First, this is what's running: This is the error when jobs are run or the... (0 Replies)
Discussion started by: Katahdin
0 Replies

4. Shell Programming and Scripting

Determine BL and RL of a file

A regular ebcdic mainframe tape usually contains header information the 1st three blocks of the tape. The header information tells the computer/user more information about what is on tape. The header info is 240 bytes in length at 80 bytes each header. The 1st block/header is volume name or... (1 Reply)
Discussion started by: Linux-wannabe
1 Replies

5. Shell Programming and Scripting

How to Determine the file owner's username

I've read the following post here and I get no output from the command. I've tried changing the '$3' to $5, 7, 10...and still nothing. Ultimately what I'd like to is determine who owns the file and rename it to file_name_$USERNAME. $ uname -a SunOS sun001 5.10 Generic_118833-33 sun4u sparc... (3 Replies)
Discussion started by: nadeemsm
3 Replies

6. UNIX for Advanced & Expert Users

How to determine if a file is done copying

I have a file repository in a directory where files are copied into it by ftp or samba. Some of the ftp transfers can be slow, and some of the files can be fairly large. The files are not being used for anything in this directory other than being taken out of the directory and used by the... (2 Replies)
Discussion started by: husker_ricky
2 Replies

7. Shell Programming and Scripting

determine owner of a file

Hello, I am on a mission to determine the user of file. I have used the ls -l command but it displays permission, link, user, group, etc, but I just want to display just the name of user of a specified file. Many thanks (4 Replies)
Discussion started by: unibboy
4 Replies

8. Shell Programming and Scripting

determine file type with perl

Hello i will like to know please how can i determine file type inside perl script not using the unix "file" program Thanks allot (1 Reply)
Discussion started by: umen
1 Replies

9. UNIX for Dummies Questions & Answers

determine the size of a file???

Hello, Can someone please tell me which command to use to determine the size of a file? When I log in to my shell account, I do this $>% ls -als total 632 8 -rw-r--r-- 1 user01 devgrp1 1558 Jul 30 23:25 .kshrc What is "1158"? Bytes? Kilobytes? I apologize if my... (8 Replies)
Discussion started by: alan
8 Replies

10. UNIX for Dummies Questions & Answers

How to determine if a file is ASCII?

I'm writing a script that takes a filename as an argument, which determines the "file type" of the file. I want to know if there is any command I can use to determine if a file is ASCII type, thanks all for giving a help. (11 Replies)
Discussion started by: popo
11 Replies
Login or Register to Ask a Question