pclose() hangs and never return in multi-threaded program
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
the file /home/ftp/testfile.gz looks ok but its size is 0.
i try to look up into it and attach to PID 1065 with gdb, the backtrace comes out as below:
Code:
(gdb) bt
#0 0x40109588 in _IO_proc_close () from /lib/libc.so.6
#1 0x40110ec8 in _IO_file_close_it () from /lib/libc.so.6
#2 0x40107860 in fclose () from /lib/libc.so.6
#3 0x000f9a64 in generate_testfile ()
#4 0x00101ddc in handleMsgFromClient ()
#5 0x00102c94 in work_pthreadMain ()
#6 0x40056a74 in pthread_start_thread () from /lib/libpthread.so.0
#7 0x401776c8 in clone () from /lib/libc.so.6
#8 0x401776c8 in clone () from /lib/libc.so.6
Previous frame identical to this frame (corrupt stack?)
(gdb)
btw, "myserver" is a multi-threaded program using pthread library.
i have no idea why fclose() hangs here, and the child process would not exit as before.
The "STAT" column is "S" for these two "gzip" processes both, i've looked into it already. They were not zombies, definitely.
It seems that the "gzip" command was still waiting for an "EOF" from standard input, but "pclose()" hung during "fclose()" call and never returned.
Is that true?
Yes, this is the interpretation I would have given.
I would strace the server program and pipe the output through egrep 'pipe|fork|close|wait' (remember strace writes to stderr). With a little work you should be able to make sure the server-side descriptor created by popen (with pipe) is closed (with pclose) before it waits for the shell process to exit. You might also make sure the other end of the pipe is closed by the server after forking.
If you can, run the server with strace just enough for the hang to happen. If it isn't too lengthy, post the strace output filtered through the egrep command above.
Kevin Barry
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.