Get Process Table of a Process/PID - Minix

This is a discussion on Get Process Table of a Process/PID - Minix ; Hi, We are working on a project where we need to return a list of processes that have a specific file open. We have a way of getting the inode of the file. So the only way I can think ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Get Process Table of a Process/PID

  1. Get Process Table of a Process/PID

    Hi,

    We are working on a project where we need to return a list of processes that have a specific file open. We have a way of getting the inode of the file. So the only way I can think of doing this is to find all the running processes with ps, take the PID's and then search the process tables for the file descriptors and then find the inode to see if it matches with that files inode. If anyone thinks this is wrong or has a better idea please let me know.

    I am not sure of how to get a processes process table. Of course after this I have to access the file descriptors, get the Inodes, and then compare. Any help would be greatly appreciated.

    Thank you in advance for your help!!!!

  2. Re: Get Process Table of a Process/PID

    So, if I understand you correctly you are looking to get the PID of a given NODE ID. However, if you know what files you want, can't you simply use lsof to find the both the PID and NODE ID?

    Code:
    Monsi:fixunix monsi$ lsof -f -- /tmp/.helo.swp
    COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
    vim     1435 monsi    4u   REG   14,2    12288 15964480 /private/tmp/.helo.swp
    Monsi:fixunix monsi$ lsof -t -f -- /tmp/.helo.swp
    1435
    Monsi:fixunix monsi$ ps aux 1435
    USER    PID  %CPU %MEM      VSZ    RSS   TT  STAT STARTED      TIME COMMAND
    monsi  1435   0.0  0.0  2437696   2020 s002  S+   11:06PM   0:00.03 vim helo
    Monsi:fixunix monsi$
    In the example above I simply use lsof with the flag "-f" to specify a file I know to be in use (/tmp/helo). By doing this I get the NODE ID but I also get the PID as well.
    In the Second command I use the flag "-t" to specify that I only want the PID(s) and if I wanted to I could send that to the kill command.
    Now, in the third command above I used the command "ps aux" and passed it the PID and came up with the same file being edited as in the lsof previously.

    Let me know if this helps. If you have any examples that you would like to share that would help as well.

  3. Re: Get Process Table of a Process/PID

    Quote Originally Posted by monsi View Post
    So, if I understand you correctly you are looking to get the PID of a given NODE ID. However, if you know what files you want, can't you simply use lsof to find the both the PID and NODE ID?

    Code:
    Monsi:fixunix monsi$ lsof -f -- /tmp/.helo.swp
    COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
    vim     1435 monsi    4u   REG   14,2    12288 15964480 /private/tmp/.helo.swp
    Monsi:fixunix monsi$ lsof -t -f -- /tmp/.helo.swp
    1435
    Monsi:fixunix monsi$ ps aux 1435
    USER    PID  %CPU %MEM      VSZ    RSS   TT  STAT STARTED      TIME COMMAND
    monsi  1435   0.0  0.0  2437696   2020 s002  S+   11:06PM   0:00.03 vim helo
    Monsi:fixunix monsi$
    In the example above I simply use lsof with the flag "-f" to specify a file I know to be in use (/tmp/helo). By doing this I get the NODE ID but I also get the PID as well.
    In the Second command I use the flag "-t" to specify that I only want the PID(s) and if I wanted to I could send that to the kill command.
    Now, in the third command above I used the command "ps aux" and passed it the PID and came up with the same file being edited as in the lsof previously.

    Let me know if this helps. If you have any examples that you would like to share that would help as well.
    I don't think minix has the lsof method you are talking about.

+ Reply to Thread