one liner to 'ps' on all processes which have file open under given directory

I found 2 interesting behaviour on 2 commands I often use.

  1. fuser
    All it outputs to stdout is PID and ' '(space).  Filename/dirname and file open code is output to stderr.
  2. ps  -p
    It does 'uniq' on process list. i.e.) It only output result once when duplicate PIDs are given command line. Also, ps is not sensitive about spurious ',' delimeter.

Here is the one liner exploiting these 2 behaviours to know which process have file open under given directory. This is the result of /tmp dir right after Java Enterprise System 5 u1 is installed.

 

# ps -o pid,user,args -p `(fuser -uc /tmp 2>/dev/null && echo "")|sed 's/ \\{1,8\\}/,/g'`
PID USER COMMAND
5718 root webservd -d /var/opt/SUNWwbsvr7/admin-server/config -r /opt/SUNWwbsvr7 -t /tmp/
5719 root webservd -d /var/opt/SUNWwbsvr7/admin-server/config -r /opt/SUNWwbsvr7 -t /tmp/
5947 root webservd -d /var/opt/SUNWwbsvr7/https-my_host.domain/config -r /opt/SUNWw
6047 bipsupp webservd -d /var/opt/SUNWwbsvr7/https-my_host.domain/config -r /opt/SUNWw
9337 root /usr/jdk/instances/jdk1.5.0/bin/java -Djava.class.path=/opt/SUNWjdmk/5.1//lib/j
15032 root /usr/jdk/jdk1.5.0_12/bin/java -Xms4M -Xmx128M -Dcom.sun.management.jmxremote -D
15758 root /opt/SUNWappserver/appserver/lib/appservDAS domain1
15769 root /usr/jdk/entsys-j2se/bin/java -server -cp /usr/bin/../../usr/share/lib/imq/imqb
15778 root /opt/SUNWappserver/appserver/lib/appservAgent my_host

 

Now, I need to ask my colleague what these processes are doing. :) 

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today