#!/bin/ksh # # filesopened - List all files opened, and open() status by PID or process name # # Dietrich von Bern # William Favorite # usage() { print "filesopened - List all files opened, and open() status by PID or process name" print " Usage: filesopened <-d> [ PID | process_name ]" print " -d will cause script to exit when process exits." } pidnum=0 prname= dieonexit=0 ### Parse paramaters while getopts ":d" opt do case $opt in d) dieonexit=1 ;; h) usage ; exit 0 ;; *) print "ERROR: Unknown command line option." ; usage ; exit 1 ;; esac done shift $(($OPTIND -1)) if [[ -z ${1} ]] then print "ERROR: Missing PID or process name paramater." print usage exit 1 fi if echo ${1} | grep -E '^[0-9]*$' > /dev/null then print "INFO: Input is read as a PID." pidnum=${1} else print "INFO: Input is read as process name." prname=${1} fi if (( ${pidnum} > 0 )) then probevue < 0 ) printf("Success\n"); else printf("Fail\n"); } @@syscall:${pidnum}:exit:entry when ( ${dieonexit} == 1 ) { exit(); } /* @@END { printf("Ending.\n"); endt = timestamp(); totalt = diff_time(begint, endt, MILLISECONDS) / 1000; printf("Time watched: %ld h %ld m %ld s\n", totalt / 3600, (totalt % 3600) / 60, totalt % 60); } */ EOF fi if [[ ! -z ${prname} ]] then probevue < 0 ) printf("Success\n"); else printf("Fail\n"); } @@syscall:*:exit:entry when ( ( __pname == \"${prname}\" ) && ( ${dieonexit} == 1 ) ) { exit(); } @@END { printf("Ending.\n"); endt = timestamp(); totalt = diff_time(begint, endt, MILLISECONDS) / 1000; printf("Time watched: %ld h %ld m %ld s\n", totalt / 3600, (totalt % 3600) / 60, totalt % 60); } EOF fi