Sample Header Ad - 728x90

How to correctly use strace -e read=fd option?

5 votes
1 answer
7255 views
I'm trying to monitor read activity on a particular file descriptor in a running process. Here is the C++ test bench I'm testing various solutions on:
#include 
#include 
#include 
#include 

int main()
{
	const int fd1=open("/tmp/testfile", O_RDWR|O_CREAT);
	const int fd2=open("/tmp/testfile", O_RDONLY);
	write(fd1, "Hello, world!", 13);
	std::cout
But strace manual says about -e read=set: > Note that this is independent from the normal tracing of the read system call which is controlled by the option -e trace=read. So I suppose that my trace=none, which is supposed to avoid tracing anything unrelated to my read=3 option is correct. Apparently, I'm doing something wrong. So, how should I actually use strace to trace only the read system call, and only when fd==3? Note that filtering output using grep is not an option, since it'd slow down a real-world application I'm going to trace.
Asked by Ruslan (3429 rep)
Jan 15, 2020, 10:47 AM
Last activity: Apr 3, 2024, 08:23 AM