Running it with
strace -e trace=open,close,read,write,connect,accept your-command-here
would probably be sufficient.
You'll need to use the -o
option to put strace's output somewhere other than the console, if the process can print to stderr. If your process forks, you'll also need -f
or -ff
.
Oh, and you might want -t
as well, so you can see when the calls happened.
Note, you may need to tweak the function call list depending on what your process does - I needed to add getdents
for example, to get better sample using ls
:
$ strace -t -e trace=open,close,read,getdents,write,connect,accept ls >/dev/null
...
09:34:48 open("/etc/ld.so.cache", O_RDONLY) = 3
09:34:48 close(3) = 0
09:34:48 open("/lib64/libselinux.so.1", O_RDONLY) = 3
09:34:48 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@V\0\0\0\0\0\0"..., 832) = 832
09:34:48 close(3) = 0
...
09:34:48 open("/proc/filesystems", O_RDONLY) = 3
09:34:48 read(3, "nodev\tsysfs\nnodev\trootfs\nnodev\tb"..., 1024) = 366
09:34:48 read(3, "", 1024) = 0
09:34:48 close(3) = 0
09:34:48 open("/usr/lib/locale/locale-archive", O_RDONLY) = 3
09:34:48 close(3) = 0
09:34:48 open(".", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
09:34:48 getdents(3, /* 5 entries */, 32768) = 144
09:34:48 getdents(3, /* 0 entries */, 32768) = 0
09:34:48 close(3) = 0
09:34:48 write(1, "file-A\nfile-B\nfile-C\n", 21) = 21
09:34:48 close(1) = 0
09:34:48 close(2) = 0
Best Answer
The console standby for this is
top
, but there are alternatives like my favoritehtop
that give you a little more display flexibility and allow you a few more operations on the processes.A less interactive view that is better for use in scripts would be the
ps
program and all it's relatives.Edit: Based on your clarified question, you might note that
strace
handles watching system calls made by a given process including all read-write operations and os function calls. You can activate it on the command line before the program you want to track or attach to a running process by hitting s on a process selected inhtop
.