Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Finding out by one process a filename opened by another process.

by Jeppe (Monk)
on Aug 01, 2012 at 10:21 UTC ( [id://984751]=note: print w/replies, xml ) Need Help??


in reply to Finding out by one process a filename opened by another process.

If you have the PID, then the shell command lsof -p will list all files opened by that PID. Also, lsof <filename> will list the processes that have opened a specific file. Etc.

lsof is a very powerful command, and it requires root access, so you'll have to provide password-less sudo access for the user executing the script in order for this solution to work.

  • Comment on Re: Finding out by one process a filename opened by another process.

Replies are listed 'Best First'.
Re^2: Finding out by one process a filename opened by another process.
by Jeppe (Monk) on Aug 01, 2012 at 10:52 UTC

    Upon further consideration, it looks to me like you might want to simply build a perl package with system constants, or use a system-wide configuration file, depending upon what precisely your application does.

    Using shared memory is also an option if the name of the pipe will change, the server application will then write the filename of the pipe to shared memory with a pre-determined shared memory key, and the client will then read the value from shared memory. IPC::ShareLite may be all you need.

      Another approach is to write the filename (w/ its path) to a file - by forked process, then another process (waiting for the keypress) will simply read the file and get the filename w/ its path. - But I do like it because app. optimimum - that I prefer - forked process will write each file as it processes it, where waiting for key press - only now and then will use the file.
Re^2: Finding out by one process a filename opened by another process.
by humble (Acolyte) on Aug 01, 2012 at 15:46 UTC
    Here (w/ my question) I pursue 2 goals:

    1. move part of my code written in BASH to PERL

    2. avoid "wide characters".

    Therefore:

    1. I'm lookign for PERL technique - how to implement this in PERL. I have done that already using BASH or OS tools, though.

    2. I'm boring w/ wide characters problem - it just makes me seek. - The more I try to go PERL way, the more problems I get - that seems to me unresolvable. F.e.: trying to fix it PERL way - I have to module Encode w/ its functions en/de -code - the great and unresolvable problem here is that I have to guess right encoding - and no automation - of course on a batch processing script like mine - it is hardly implemetable solution. - At other hand, using BASH/OS tools incapsulations to my PERL code, blesses me w/ no such a problem - a work around have been found in opening /proc/PID/cmdline - that has the filename and its path in purity - allowing me to access the file farther by PERL code.

    So, having said that, I'm wondering if it is the way to go? Or there some techniques that I'm not aware of, and I can use PERL for my situation?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://984751]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 16:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found