Use Unix truss command to monitor all operations and activity on a file

Hi Guys,
Can someone please give me an example of how to use the truss command to monitor all operations on a particular file.

I know there is an -r switch and reference to a file descriptor - but sure if this is simply a name of a file which you have to pass in or something different


 B Cunney

LVL 17
Barry CunneyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

A file descriptor is an integer that represents the file information in the kernel.

By convention, 0 is stdin, 1 is stdout, and 2 is stderr, so '-r 0' would mean monitoring reads to stdout.

If a program opens a fixed set of files, you can run truss against it to figure out what file descriptor ends up going to which file (by looking at the return value of the 'open' call).

If it opens different files based on user input, you'll proobably have to monitor all file descriptors since you won't know in advance which one goes with the file name you're interested in.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Barry CunneyAuthor Commented:
Cheers chris,
I thought that there might be some trick one could use to get the truss command just to trace operations on one file
You could probably write a perl script that monitors the output of truss and figures out which lines refer to a file of a particular name...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.