Trouble understanding strace of a process

644 views Asked by At

I have a perl script running as daemon. It hits a database every 10 seconds and if there are any jobs in the queue, it spawns a separate shell to execute an individual job. But very often script fails to fetch jobs from database.

Ideally there should be calls to DB like

read(3, "\3def\3job\rqueueb\7JobTy"..., 55) = 55
read(3, ";\0\0\6", 4)                   = 4

Below is the strace of this daemon/process. Is it waiting for something? I appreciate any help.

pipe([6, 7])                            = 0
pipe([8, 9])                            = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0) = 31858
close(9)                                = 0
close(7)                                = 0
read(8, "", 4)                          = 0
close(8)                                = 0
fcntl64(6, F_GETFL)                     = 0 (flags O_RDONLY)
fstat64(6, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xfffffffff7783000
_llseek(6, 0, 0xffd4e540, SEEK_CUR)     = -1 ESPIPE (Illegal seek)
fstat64(6, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
read(6, "", 4096)                       = 0
close(6)                                = 0
munmap(0xf7783000, 4096)                = 0
rt_sigaction(SIGHUP, {SIG_IGN, [], 0}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGINT, {SIG_IGN, [], 0}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGQUIT, {SIG_IGN, [], 0}, {SIG_DFL, [], 0}, 8) = 0
waitpid(31858, 0xffd4e670, 0)           = -1 ECHILD (No child processes)
rt_sigaction(SIGHUP, {SIG_DFL, [], 0}, NULL, 8) = 0
rt_sigaction(SIGINT, {SIG_DFL, [], 0}, NULL, 8) = 0
rt_sigaction(SIGQUIT, {SIG_DFL, [], 0}, NULL, 8) = 0

And this is immediately repeated (at least) twice more.

1

There are 1 answers

0
ikegami On

That creates a child process (clone), tries to obtain data from it (read 6). The child closed the pipe, so the read returns EOF (0). This is taken to be a sign that the child has exited, so it tries to reap the child (waitpid). This fails (-1), which means $SIG{CHLD} must have been set to IGNORE. The status might have been useful.

The presence of the 8/9 pipe indicates the child will call exec. The pipe is used to notify the parent of an error manipulating file handles or calling exec. The child would have set 9 to close-on-exec, so receiving an EOF without any data from this pipe (as is the case here) indicates the exec was successful.