hi, i need to find out no of times a file has been opened,but not yet closed. i mean if a file has been opened for 2 times ,one for reading and another for writing and the file has not been closed,the script should display the count of total opens and also to check wheather it has been closed r not. This message posted from opensolaris.org
Brendan Gregg
2006-May-09 13:34 UTC
[dtrace-discuss] Dtrace Script to find instances of a file
G''Day Ramesh, On Tue, 9 May 2006, ramesh wrote:> hi, > > i need to find out no of times a file has been opened,but not yet > closed. > > i mean if a file has been opened for 2 times ,one for reading and > another for writing and the file has not been closed,the script should > display the count of total opens and also to check wheather it has been > closed r not.Done properly, this could be a short script using the syscall::: provider. If you wanted a quick and dirty answer, try the following one-liner, # dtrace -n ''fbt::fop_open:entry { @[stringof((*args[0])->v_path)] sum(1); } fbt::fop_close:entry { @[stringof(args[0]->v_path)] = sum(-1); }'' Which gathers entropy for the opens and closes by the cached vnode pathname; a positive number indicates more opens than closes. no worries, Brendan [Sydney, Australia]