SUMMARY: 2 Q's: When file is open, and when file is PS

From: Morten K. Barfoed (
Date: Tue Jun 06 1995 - 03:41:51 CDT

Hi all.

My original posting:

----- Begin Included Message -----
Dear sun-managers.

I have 2 easy questions for you:

1: How do I check if a file is opened by some process?
        At the prompt, and in a C-program ?

        I want to be able to decide when a file that is being
        transferred by FTP has been written in it's entirety,.

2: Do you know of a utility that will tell me if a file
        is a PostScript-file? I have a file that the unix-command
        'file' sees as a ascii-text, while GhostView displays
        it as a PostScript-file. one of my scripts needs to know
        what kind of file it is.
 ----- End Included Message -----

First of all sorry for not mentioneing my OS, it's SUNOS 4.1.3,
but I'm also interested in responses for Solaris 2.x

Thanks you all for a lot of quick response, you are too many to
mention, so none mentioned, none forgotton.

Re. Q1:

test: One suggested to run 'test' with appropriate switch, but I
        haven't been able to decide which switch could be appropriate.

ftp: The same responder mentions that ftp returns the size of the
        block actually transferred. I'll have ftp running and need to
        decide whether it has terminated the transfer from another
        process, so I don't think I can use that, but I'll dig a bit
        deeper into ftp.

fuser: fuser is a command in the os which can decide which processes
        are using a file. I have tried to make a simple test with
        this utility: I open a file, and write 10Mbytes, one by one.
        While that is going on, I run fuser on the file. But nothing
        is reported ! Perhaps that's the wrong way to use it (?) or
        perhaps 'using a file' does not include having it open and
        writing to it. I'll do some more checking on this command.

        One said to try 'fuser -f filename' but on my OS -f is not
        a legal option. Perhaps it is oin Solaris 2.x.

lsof: This is public-domain software, which we have already. I ran the
        test described above with this utility also, it did not report
        anything (do I have an old version ?).

ruser: Was mentioned by one. Is it public domain or a typo (xarchie
        didn't find it !)

ofiles: I have retrieved this from

        Unfortunately it does not work under SunOS 4 ! It says so in
        the README-file, so I didn't even try.

fcntl: One suggested to try with fcntl (a c-routine). I have read through
        the documentation but couldn't find the right method of using it.

lockf: The same person suggested that perhaps lockf could be usefull.
        I believe that using this routine requires that the process
        that has the file open, has locked part of or the whole file.
        I'll check if ftp uses file-locking.

Other: One told me that he's been looking for 2 years for a way of
        doing it (I guess he's been doing other stuff as well), but
        has found no other way than checking with regular intervals
        if the file has been changed, using the stat-command.

Well appearantly this was a hard one ! I'll do some further checking
on some of the suggestions, but I'm not overly optimistic :-{

Re Q 2:

The answers here can be summarized as follows:

%!PS: The OS command 'file' should normally be able to tell me
        if a file is a PostScript-file. If it doesn't I might need
        to add the following entry to the file called /etc/magic:

        0 string %! PostScript document

        This because the first 4 characters in a Adobe PS-file should
        be %!PS.

        Alternatively I could use that simple fact to write a small
        script or program returning some specific value when a PostScrip
        file is found.

        One suggested this, and I'm retrieving it right now, to have a

Unfortunately my PS-file does not contain these letters ! So I believe
that it's not a standard PS file. What buggles me is that GhostView can
recognize it. I guess that GhostView doesn't check for the mentioned
first line but just starts to interpret the file.

What I didn't tell you in my original posting was, that I need the
ability to decide filetype in a print-filter. I think I'll just demand
standard PS files, if I can get away with that, it's the simplest.

Thanks again you guys and girls.

Morten Krabbe Barfoed

Danish Space Research Institute phone: +45 45 88 22 77 (switch-board)
Gl. Lundtoftevej 7 phone: +45 45 87 40 77 - 161 (direct)
DK 2800 Lyngby FAX: +45 45 93 02 83
Denmark e-mail:

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:10:26 CDT