1

all I've been trying to get apache to run in signal process / debug mode,in order to use callgrind with it, and have a simple single process to work with for debugging.

Does anyone have experience with running apache in single process mode?

I've tried running httpd -X. This can start apache with a single process, (good) but have not found a clean way of shutting them down again, when running like this. Only way that works is a kill -9. which blows away any debugging output as well, so does not get me any further ahead, when using callgrind. The complete command I am running, for those interested is:

valgrind --tool=callgrind  /path/to/apache2/httpd -X

Any ideas appreciated.
Thanks

Shreyos Adikari
  • 12,348
  • 19
  • 73
  • 82

2 Answers2

1

There are two issues that need to be overcome:

  1. Apache needs a bunch of environment variables
  2. Apache drops from root user to apache/www-data, which stops valgrind from writing files

On ubuntu this should do the trick:

source /etc/apache2/envvars
valgrind --tool=callgrind /usr/sbin/apache2 -X

On RHEL/centos/fedora (untested):

source /etc/sysconfig/httpd
valgrind --tool=callgrind /usr/sbin/httpd -X

Once loaded, before hitting the site, make the callgrind files world writable (valgrind will delete the temp files when done):

chmod 777 /tmp/vgdb* callgrind*

When done, remember to change the permissions of your callgrind file to something more secure.

Here's my blog post chronicling my struggle to make this work myself.

matiu
  • 7,469
  • 4
  • 44
  • 48
0

A simple kill -TERM directed at the apache process should tell it to shutdown.

TomH
  • 8,900
  • 2
  • 32
  • 30
  • When I use "kill -9", httpd is killed, but valgrind can not write cache simulation file, I can not get any result from valgrind. – user1859969 Nov 29 '12 at 02:45
  • Yes `kill -9` will cause the kernel to terminate the process with no further chance for it to run and as valgrind is part of the same process it will not be able to do any final reporting. That is why I said to use `kill -TERM` instead. – TomH Nov 29 '12 at 09:55
  • I have tried the command "kill -TERM httpd's pid". But it acts the same as kill -9 and valgrind output error "cannot open cache simulation output file". >< I am confused. – user1859969 Nov 30 '12 at 03:07
  • Right, so that is an entirely different issue - the very fact that you get that error means than valgrind has got control and is trying to output data. Most likely it doesn't have permission to write to the default location so try using `--callgrind-out-file=` to specify a location it can write to. – TomH Nov 30 '12 at 08:43
  • I have tried the --callgrind-out-file , can not make any difference. I am sure I have permission, because I run my command as a root user. – user1859969 Nov 30 '12 at 11:24