libexpect sigalrm nanosleep crash

时间:2015-08-05 18:23:42

标签: linux multithreading signals sleep

我正在使用libexpect,但如果读取超时(预期返回代码EXP_TIMEOUT),我会发生崩溃,如下所示。

    Program terminated with signal SIGABRT, Aborted.
#0  0x00007f1366275bb9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56  ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  0x00007f1366275bb9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007f1366278fc8 in __GI_abort () at abort.c:89
#2  0x00007f13662b2e14 in __libc_message (do_abort=do_abort@entry=2, fmt=fmt@entry=0x7f13663bf06b "*** %s ***: %s terminated\n") at ../sysdeps/posix/libc_fatal.c:175
#3  0x00007f136634a7dc in __GI___fortify_fail (msg=<optimized out>) at fortify_fail.c:37
#4  0x00007f136634a6ed in ____longjmp_chk () at ../sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S:100
#5  0x00007f136634a649 in __longjmp_chk (env=0x1, val=1) at ../setjmp/longjmp.c:38
#6  0x00007f1366ed2a95 in ?? () from /usr/lib/libexpect.so.5.45
#7  <signal handler called>
#8  0x00007f1367334b9d in nanosleep () at ../sysdeps/unix/syscall-template.S:81
#9  0x000000000044cc13 in main (argc=3, argv=0x7fffca4013b8) at main_thread.c:6750
(gdb) 

正如你所看到的,我正在使用nanosleep,它应该不会与usleep和sleep(http://linux.die.net/man/2/nanosleep)之类的信号相互作用。据我了解,libexpect使用SIGALRM超时,但我不清楚这两个线程是如何交互的。如果我不得不猜测,期待的电话会引发一个声音,它会打断纳米电话,但除此之外,我不知道发生了什么。

主题1:

while (stuff)
{
    //dothings
    struct timespec time;
    time.tv_sec = 0.25;
    time.tv_nsec = 250000000;
    nanosleep(&time, NULL);
}

主题2:

switch(exp_expectl(fd, exp_glob, (char*)user_prompt, OK, exp_end))
{
case OK:
    DG_LOG_DEBUG("Recieved user prompt");
    break;
case EXP_TIMEOUT:
    DG_LOG_DEBUG("Expect timed out");
    goto error;
default:
    DG_LOG_DEBUG("Expect failed for unknown reasons");
    goto error;
}

我已经完成了一些有关信号和睡眠的阅读,但我曾多次在多线程中使用过睡眠,直到现在还没有遇到任何困难。我错过了什么?

edit: misc version info ubuntu 14.04 3.13.0-44-generic /usr/lib/libexpect.so.5.45 code is in C compiler is gcc (-lexpect -ltcl) include <tcl8.6/expect.h>

0 个答案:

没有答案