Linux: Trace file system activity of a process

To trace file system activity of a process the Linux utility strace can be used. strace traces all system calls, but using the -e trace=file option gives a nice output about file system activity of a given process. This gives a similar output to the SysInternals Process Monitor which I used sometimes on Windows.

In order to use the utility for a multithreaded program (like Java) the -f parameter helps too. Using the output of strace (blue text) I could manage to find a missing file which crashed a Java program:

 [pid 5997] open("/home/sag/My Documents/BookSmartData/log-2013.04.11-00.29.57.txt", O_RDWR|O_CREAT|O_EXCL, 0666) = -1 ENOENT (No such file or directory)
 java.io.IOException: No such file or directory
 at java.io.UnixFileSystem.createFileExclusively(Native Method)
 at java.io.File.createNewFile(File.java:947)
 at com.blurb.booksmart.util.vent.Vent.writeLogFile(Vent.java:388)
 at com.blurb.booksmart.util.vent.Vent$ExceptionHandler.handle(Vent.java:369)
 at com.blurb.booksmart.util.vent.Vent$BookSmartThreadGroup$1.run(Vent.java:510)
 at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
 at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)
 at java.awt.EventQueue.access$200(EventQueue.java:103)
 at java.awt.EventQueue$3.run(EventQueue.java:688)
 at java.awt.EventQueue$3.run(EventQueue.java:686)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
 at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
 at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
 at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

Leave a Comment