[Qt-interest] bash jobcontrol breaks QT4 and inotify ?
Tijl Coosemans
tijl at coosemans.org
Tue Aug 17 10:57:44 CEST 2010
On Tuesday 17 August 2010 10:06:32 David Heremans wrote:
> On 08/13/2010 07:29 PM, Andreas Pakulat wrote:
>> On 13.08.10 15:09:41, David Heremans wrote:
>>> I was trying to find a nice way to have my program react upon new files
>>> that could pop-up in a given /var/spool directory. Since it runs on a
>>> linux box I thought about using inotify, and a quick Google got me to
>>> this page:
>>>
>>> http://wahjava.wordpress.com/2007/05/09/my-experiment-with-inotify-and-qt4/
>>>
>>> I downloaded the small example inotify.tgz and it worked as a charm so I
>>> decided to try to integrate the inotify.hh and inotify.cc into my
>>> program, but it doesn't seem to work correctly, so I had to look at the
>>> example again and (by accident) I found the following strange behavior.
>>>
>>> If I launch the ./inotify_demo (from an xterm/konsole) and start
>>> monitoring a directory it works nicely. But if a press CTRL-Z and bring
>>> it back to the foreground (with the fg command) it simply stops reacting
>>> to changes? Even pressing the stop/start button doesn't reactivate the
>>> program.
>>>
>>> Can somebody here explain me the impact of the CTRL-Z on the inotify
>>> mechanism? Could it be that running my program in the debugger doesn't
>>> work because of some unknown-to-me impact from signals (on the threads?)
>>>
>>> I'm running kubuntu lucid lynx (64 bit)
>>> with qtcreator 1.3.1, based on qt 4.6.2(64 bit)
>>
>> Why are you using inotify at all instead of using Qt's existing api to
>> watch files/dirs: QFileSystemWatcher? It uses inotify on Linux and
>> whatever the OS provides on other platforms. And it still works after
>> Ctrl+Z; fg.
>
> I'm still puzzled by this program going hay-wire after a 'Ctrl+Z;fg'
> I found out the following extra info. I monitored the program with htop
> so that I could se the threads and when I launch the program I get
> 7577 david 20 0 249M 21456 1584 S 0.0 0.4 0:00.10 ./inotify_demo
> 7578 david 20 0 249M 21456 1584 S 0.0 0.4 0:00.00 ./inotify_demo
> 7579 david 20 0 249M 21456 1584 S 0.0 0.4 0:00.00 ./inotify_demo
>
> which should be the main process and two threads
> If I press CTRL-Z
> the stae of all 3 goes from S(leeping) to T(Traced/stopped)
>
> However after giving the fg command
> 7577 david 20 0 249M 21456 1584 S 0.0 0.4 0:00.18 ./inotify_demo
> 7578 david 20 0 249M 21456 1584 S 0.0 0.4 0:00.00 ./inotify_demo
>
> It seems that the last thread has vanished!
>
> When I try to performs strace(pressing s in htop) upon those 3 pids
> created initialy the first is the one sending output to the console, and
> I see read poll events passing by, and everything keeps working. The
> second pid doesn't produce any output but still everything works. Howver
> when trying to start an strace on the 3th one the output I get this
>
> close(14)
> close(15)
> madvise(0x7f844d627000, 8368128, MADV_DONTNEED) = 0
> _exit(0)
>
> And afterwards the program doesn't read the changes in the directory
> anymore
>
> So it seems that trying to trace/debug the program will also cause it
> to break...
>
> Can anybody tell me wat is going on here? Or provide some pointers as
> where to go from here on so that I understand what is going on..
When a thread is interrupted by a signal while in a syscall (in this
case read(2), inotify.cc line 86), the syscall returns -1 and sets
errno to EINTR.
Currently the inotify thread exits on every error. It should test for
EINTR and restart the loop in that case.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 228 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100817/d3886307/attachment.bin
More information about the Qt-interest-old
mailing list