Created
          January 30, 2024 15:18 
        
      - 
      
 - 
        
Save jordiclariana/eecd5173dadaf18c98c07db8fac2ee47 to your computer and use it in GitHub Desktop.  
    List watched files by a PID
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/env bash | |
| set -e | |
| LIST="$(grep inotify /proc/"$1"/fdinfo/* | \ | |
| awk '{print $3,$4}' | \ | |
| sed -r 's/ino:([^ ]+) sdev:(.{2})(.*)/\1 \2 \3/' | \ | |
| while read -r inode devmajor devminor; do | |
| dec_inode=$((16#$inode)) | |
| dec_devmajor=$((16#$devmajor)) | |
| dec_devminor=$((16#$devminor)) | |
| echo "$dec_inode" #$dec_devminor $dec_devmajor" | |
| done | |
| )" | |
| PROC_CWD=$(realpath /proc/"$1"/cwd) | |
| count=0 | |
| M=("-inum 0") | |
| for i in $LIST; do | |
| count=$((count+1)) | |
| M+=("-o -inum $i") | |
| if [ "$count" -eq 500 ]; then | |
| sudo find "$PROC_CWD" \( ${M[@]} \) -print | |
| M=("-inum 0") | |
| count=0 | |
| fi | |
| done | |
| if [ "$count" -gt 0 ]; then | |
| sudo find "$PROC_CWD" \( ${M[@]} \) -print | |
| fi | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment