In Linux, web programs generally run in two ways: Linux Enterprise applications-Linux server applications. For details, see the following. 1. directly processed by the httpd process, such as the module-based php
2. cgi programs generated by httpd subprocesses are processed. httpd subprocesses are only responsible for input and output.
Generally, observing the running behavior of a program uses strace is very helpful for the command line program, but it is not very easy for a web request, because there are so many httpd sub-processes, it is hard to say which httpd sub-process the request is in. However, there are two tips:
1. Use httpd. conf to limit the maximum number of httpd sub-processes to 1, so that the httpd sub-process can be processed, and the strace-p pid can be used directly.
2. Use commands
Pids = 'ps aux | grep httpd | awk' BEGIN {str = "" ;}{ str = str "-p" $2 "";} END {print str} ''; strace-o httpd. strace $ pids
Trace all httpd sub-Processes
The above two methods are good for the first method of execution, but it is difficult for the second method, because the generated sub-process is transient and you have no time to see it, so let's take a look at the following two tips:
1. Do I still use strace to capture the pid? Actually, it is okay. Don't forget the-f-F parameter of strace. As long as you check the parent process, the sub-process crashes and wants to run away. The command is as follows:
Pids = 'ps aux | grep httpd | awk' BEGIN {str = "" ;}{ str = str "-p" $2 "";} END {print str} ''; strace-f-F-o httpd. strace $ pids
More-f-F than the preceding command
2. Don't debug through the web. It's too low-level and interesting. Just execute strace in the command line. How can we pass the parameter? Oh, here we will introduce:
For example, the cgi program abc. cgi requires get parameters a, B, and c, and the restricted access ip address is 10.10.10.10. write the script debug_abc.sh as follows:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service