Hi all,
while trying to debug and figure out why a lofiadm command was not working on my script, i came across a cmd called "truss"
all i know about it is that it executes the specified command and produces a trace of the system calls it performs, the signals it receives, and the machine faults it incurs.
But i dont know how to use it in a script..
and how to follow the output...
am going through the man pages but its always a little easier to understand if someone explains it.
Can this be used in the middle of the script , and only to a particular process,
in this case can i use truss just for figuring out why lofiadm is not creating a block device?
even though its amidst various other commands in a script??
I would like to know more about this!!
can anyone shed some light on this?
This is what i had in my notes ( i must have picked it up from some website :-))
Just like linux loopback device solaris has lofi - loopback file driver. The lofi file driver exports a file as a block device. Reads and writes to the block device are translated to reads and writes on the underlying file.
e.g of mounting existing cd-rom image(cd.iso)
lofiadm -a /path/to/cd.iso
Output:
/dev/lofi/1
/dev/lofi/1 is the device, use the same to mount iso image with mount command:
You use truss on the same command line where you give the command you want to study. Use -o to store the output in a file or you'll get a giant scroll of stuff on your screen that will be impossible to read. Like this:
truss -o mytruss.txt myscript.sh
Where myscript.sh is what you want to learn about and mytruss.txt is the textfile to store the output in. Then just read mytruss.txt.
Now, READING the output is a whole other thing. It is very complicated if you've never seen it. No simple tips I can give you, just take a look and see what you can figure out - google stuff that doesn't make sense.
For your specific questions:
To truss an already running process use the -p flag and give the PID of the process you want to study.
To see why it isn't opening a device I guess you'd look at the open and close statements to see what isn't matching or where it breaks down. Every time your process opens or closes a file truss will tell you about it, so you may see the spot of your script/command where you expect the device to open but no file open happens.
I'm not sure about using truss within a script - to use it on a script I'd simply use truss and run the script as the command to trace.
I'm not sure if you could use it within a script on just one command. Probably could, try it on a test box I guess. But I've not done it, and didn't see any examples in the man pages of doing it that way so I can't say for sure.
Definately use it with the -o option in that case so it saves the truss output separately from whatever else your script would normally be doing.