找出UNIX守护进程卡在哪里?

时间:2013-04-23 11:12:58

标签: c debugging unix gdb daemon

多年前,我编写了一个UNIX守护进程(wsqueryd) 背景:

pid_t pid;

pid = fork();
if (pid < 0)
  misc_log_error_and_exit("Could not fork parent process");

if (pid > 0) // => this is the parent process
  exit(EXIT_SUCCESS); // terminates it

// Creates an new session for the process.
if (setsid() < 0)
  misc_log_error_and_exit("Cannot create new session");

现在,我意识到守护进程有时会卡住。我附上gdb

$ cd $DAEMON_SRC_PATH
$ ps aux | grep wsqueryd
apache   20735  [...]
$ sudo gdb wsqueryd # daemon runs as different user
[...]
(gdb) attach 20735
Attaching to program: [...]/wsqueryd, process 20735
warning: .dynamic section for "/lib/libk5crypto.so.3" is not at the expected address (wrong library or version mismatch?)
warning: .dynamic section for "/lib/libkrb5support.so.0" is not at the expected address (wrong library or version mismatch?)
Reading symbols from /usr/lib/libcurl.so.4...Reading symbols from /usr/lib/debug/usr/lib/libcurl.so.4.2.0.debug...done.
done.
Loaded symbols for /usr/lib/libcurl.so.4
Reading symbols from /usr/lib/libev.so.4...Reading symbols from /usr/lib/debug/usr/lib/libev.so.4.0.0.debug...done.
done.
Loaded symbols for /usr/lib/libev.so.4
Reading symbols from /lib/libz.so.1...Reading symbols from /usr/lib/debug/lib/libz.so.1.2.5.debug...done.
done.
[...]
(gdb) list
1       // (C) [...]
2
3       #include <stdlib.h>
4       #include <stdio.h>
5       #include "daemon.h"
6       #include "misc.h"
7       #include "retrieval.h"
8
9       int main(int argc, char *argv[]) {
10        misc_init(argv[0]); // to be called at the very beginning

如何找到守护进程被卡住的 ? (使用周围的代码,并具有单步执行的能力)

0 个答案:

没有答案
相关问题