Sometimes you are under a situation that you don’t know what’s going on with the server, it’s like a blackbox. How to get some lights in this? The answer is strace . strace is a utility that will help you see what your application is doing, what file it’s opening, what is it trying to do.
How to start?
the most common way to do is : you have a pid of your application , then just run this command:
strace -p 100
How about other cases, like you have multiple process like web server, when a server start, it will start with at least 4 processes. When you hit the URL, one of the process will serve you. We don’t know which one it is, so let trace all of them
cd /root
mkdir straces
cd straces
ps ax | grep httpd | grep -v grep | awk '{ print "strace -f -s500 -o strace."$1".log -p "$1"&" }' | sh
After this, you will see a lot of files
-rw-r--r--. 1 root root 153K Jun 8 13:14 strace.9283.log
-rw-r--r--. 1 root root 2.3M Jun 8 13:14 strace.9299.log
-rw-r--r--. 1 root root 40K Jun 8 13:14 strace.9300.log
-rw-r--r--. 1 root root 99K Jun 8 13:14 strace.9302.log
-rw-r--r--. 1 root root 34K Jun 8 13:14 strace.9303.log
-rw-r--r--. 1 root root 39K Jun 8 13:14 strace.9306.log
-rw-r--r--. 1 root root 39K Jun 8 13:14 strace.9307.log
-rw-r--r--. 1 root root 33K Jun 8 13:14 strace.9347.log
To kill straces let run this command:
killall -9 strace
By the way, if you don’t have killall, you can install it:
yum install psmisc