Need to determine Process-File association

Posted on 2005-04-24
Last Modified: 2010-04-20
I have a number of instances of MRTG running on my system which collect statistics on various switches/routers on the network and store the data in distinct directories. For e.g., for and, the graphs and data are stored in /www/servers/mrtg- and /www/servers/mrtg- The associated config files are stored in /home/mrtg/mrtg- and /home/mrtg/mrtg- There are about 50 such instances of mrtg running for 50 different devices. I wanted to find out which instance of mrtg is associated with which data file. Running ps -ef | grep mrtg returns all of my mrtg processes and their PIDs. I parse the output and feed it to 'lsof -p PID' and this returns a number of associated files, but no mention of my /www/servers/mrtg-XX data files.

What am I doing wrong? Regarding my MRTG, I'm not using RRDTOOL, and the MRTG data collector starts up every 5 minutes for data collection.

- Faheem
Question by:ccsenet
    LVL 3

    Accepted Solution

    it is probably because /www/servers/mrtg-XX data files are not held open by your mrtg processes. Every 5 minutes it opens the file, writes the data and closes the file. So you could say it's working as designed and you're doing nothing wrong.

    If it is critical for you to have this functionality, you could change mrtg (it is perl script, so you can change it). You could add a part which writes current pid to your log file. You can use $$ variable to access current PID value.
    LVL 22

    Expert Comment

    You are probably not doing anything wrong. I suspect that the mrtg processes are only opening the files when they need to log data, and then closing them again. Therefore, you'll only get one of these files listed if you run lsof at the exact moment that data is being logged.

    Perhaps look at creating a seperate soft link for each of the switches/routers? That way, you'll be able to identify which is which:)
    LVL 1

    Author Comment

    Hey All,

    Thanks for answering. You were right - mrtg doesn't lock down the data file or anything between reads/writes. That was silly to think it might. I was gonna go with what dbac suggested - about working in the mrtg script, but might have found a workaround. 'lsof +D /home/mrtg/cfg' returns all processos associated with the files in the directory. So my output is somewhat like this:
    COMMAND    PID    .....  NAME
    mrtg            4178         /mrtg-
    mrtg            4193         /mrtg-

    That solved the problem for determining which mrtg instance (PID) was associated with which device. However, I dunno why '_l' is appended to the files. The file does exist in each device's respective folder, but its empty --> 0L, 0C. Probably some internal working on MRTG.. Its not as nice and clean as logging PID by changing the mrtg script would be, but works for now.

    Thanks again

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    Currently, there is not an RPM package available under the RHEL/Fedora/CentOS distributions that gives you a quick and easy way to allow PHP to interface with Oracle. As a result, I have included a set of instructions on how to do this with minimal …
    Join Greg Farro and Ethan Banks from Packet Pushers ( and Greg Ross from Paessler ( for a discussion about smart network …
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now