lsof should give all open files for a set of pids

前端 未结 2 724
温柔的废话
温柔的废话 2021-01-01 23:51

I have 30 instances of a process running on a server and want to log open files for each process for analysis.

I ran the following command:

* ps auw         


        
相关标签:
2条回答
  • 2021-01-02 00:49

    The lsof -p option takes a comma-separated list of PIDs. The way you're using xargs will pass the pids as separate arguments leading some to be interpreted as filenames.

    Try lsof -p $(your grep | tr '\012' ,) That's going to have a trailing comma, I'm not sure if lsof will care but you could sed it off if necessary.

    0 讨论(0)
  • 2021-01-02 00:51

    You can use xargs -L1 lsof -p to run lsof once per pid.

    Even better: use lsof -c to list all open files from commands matching a specific pattern:

    lsof -c bas # list all processes with commands starting with 'bas'
    lsof -c '/ash$/x' # list all commands ending with 'ash' (regexp syntax)
    
    0 讨论(0)
提交回复
热议问题