strace -f -c segfaults if I pthread_create and fcntl(F_GETFL)

D Wang dwang at
Thu Jul 17 23:11:09 UTC 2014

(Please copy dwang at on reply, as I am not subscribed to the list.)

I'd like to strace a multi-threaded program which calls fcntl
sometimes, but the combination of threads and fcntl causes strace to

Here's a small reproduction:

    cd /tmp
    cat > foo.c <<'EOF'
    #include <fcntl.h>
    #include <unistd.h>
    #include <pthread.h>

    void * thread_start(void * unused) {

    int main (int argc, char **argv) {
      pthread_t thread;

      /* ordering of these two lines does not matter */
      fcntl(1, F_GETFD, 0);
      pthread_create(&thread, NULL, thread_start, NULL);

      return 0;
    gcc -l pthread foo.c
    strace -f -c ./a.out

Looks like omitting any one of -f, or -c, or the pthread_create, or
the fcntl is enough to avoid the segfault, but unfortunately I need
all four of them.

What's going wrong?  Is there any workaround?  If not, is this
something you would fix?  (No urgency on my end, but I think this is a
reasonable thing to support eventually.)

Thanks for writing strace.


Random system info, not sure what would be helpful to you:

$ strace -V
strace -- version 4.5.19
$ uname -a
Linux tot-qws-u12112a 2.6.32-431. #1 SMP Fri Dec 13
13:06:13 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
$ rpm -q --whatprovides /usr/lib64/
$ rpm -q --whatprovides /usr/include/fcntl.h

More information about the Strace-devel mailing list