Mailinglist Archive: opensuse-programming (51 mails)

< Previous Next >
Re: [suse-programming-e] threads and file descriptors
  • From: Per Jessen <per@xxxxxxxxxxxx>
  • Date: Mon, 08 May 2006 14:39:26 +0200
  • Message-id: <e3ne5u$u1v$1@xxxxxxxxxxxxxxxx>
Jerry Feldman wrote:

> The issue here is with open(2) (and related calls that return a new
> file descriptor).
> The trace does not show that 2 different open(2) calls return 13.

I had to go quite far back to find the pipe() call that gives me a set
of 13 and 14.

> I suggest that you add some diagnostic code whenever an open(2) or
> related call returns a file descriptor.

I was hoping strace would do it for me, but it might be better just
doing it myself.

> fprintf(stderr, "Thread %ld receives fd %d\n", pthread_self(), fd);
> As I mentioned, GDB is not the best tool to trace threads.
> If you want to log the data:
> Create a log file in the parent thread.
> Create a mutex
> void logger(int fd)
> {
> pthread_mutex_lock(&lock_mutex);
> fprintf(logstream, "Thread %ld receives fd %d\n",
> pthread_self(), fd);
> fflush(logstream);
> pthread_mutex_unlock(&lock_miutex);
> }

I'll try it. Thanks.

/Per Jessen, Z├╝rich

< Previous Next >
List Navigation