Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Cocoa application error causing ps/top to hang in terminal

Cocoa application error causing ps/top to hang in terminal
Thread Tools
Forum Regular
Join Date: May 2001
Location: Mnt View, CA
Status: Offline
Reply With Quote
Jun 7, 2001, 02:42 AM
 
I have a strange problem that doesn't make any sense to me.

MY SETUP
--------
I wrote an Cocoa application to do some extensive text work. The application has two NSTextViews and one NSTableView. The table displays word by word the text from the two textviews. When I select a row in the table it highlights the selected text (setting TextColor) in both text views. It also creates a few dictionaries with the words in the texts. Some file access (simple read/write of complete files). Each textview has about 2.5MB of text.

Anyhow, when I read the text from the two textviews (I have to do some parsing) once in a while my application hangs. Clearly there is some bug in my code


THE STRANGE SIDE EFFECT
-----------------------
What is strange and what I don't understand is that, when this happens and I do ps/top in a terminal window both utilities hangs - without printing anything. I cannot even Ctrl-C them. I can open other terminal windows and all other commands that I tried seem to work fine. Seem to be some problem reading the process table.

While using my application I'm repeating the same things over and over again. One out of 100 times this happens (approx once every 45 min).

I have monitored the memory usage and my application is not leaking any memory (and I have pleanty in my machine). CPU Monitor reports no load when it hangs.

I can Option-Command-Esc and kill the application (I have to do it twice before it succeeds).

I am experience programmer and done my share of Linux/FreeBSD kernel hacking. It is clearly something in my code triggering this but I'm not doing anything advanced.

Any ideas what is causing this (memory, disk, cocoa) ?
     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Jun 7, 2001, 08:23 AM
 
I can't offer you a solution to your problem, but it sounds like what you are doing shouldn't be effecting other programs. You should submit a bug report to Apple on this. http://developer.apple.com/bugreporter
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Jun 9, 2001, 04:11 AM
 
This was discussed not long ago on darwin-development and one of the OmniGroup OS X lists. It happens when a process enters the U state, or something. It's very odd. There are archives for darwin-dev on http://www.darwinfo.org , btw.
     
Dedicated MacNNer
Join Date: Apr 2001
Location: San Francisco, USA
Status: Offline
Reply With Quote
Jun 9, 2001, 07:59 PM
 
Okay I'm running into the same problem here. In my case Mail is the 'frozen' app. I tried running ps, top and Process Viewer but they become frozen as well and don't show any output. Next I tried to attach to the Mail process using gdb and get the following message:
<font face = "courier">
Unable to attach to process-id 11824: Operation not permitted (1).
This request requires that the target process be neither setuid nor setgid and have the same real userid as the debugger, or that the debugger be running with adminstrator privileges.
</font>
When I run the command again as superuser, gdb freezes. The Sample application also freezes when I select the "Attach..." command. So basically Mail has caused some sort of deadlock in the kernel and is slowly killing my computer.

I few diagnostic commands still work, however. I am able to peek at Mail's open file descriptors using fstat. The TCP socket appears is an established connection to mail.mac.com.143 according to netstat.
<font face = "courier">
CMD PID FD INUM MODE SZ|DV R/W MOUNT
Mail 11824 wd 2 drwxrwxr-t 1078 r /
Mail 11824 0 25363076 ?rw-rw-rw- null r /dev
Mail 11824 1 25363844 ?rw------- console w /dev
Mail 11824 2 25363844 ?rw------- console w /dev
Mail 11824 3 173462 -rw-r--r-- 2918400 r /
Mail 11824 4 173449 -rw-r--r-- 488706 r /
Mail 11824 5 173463 -rw-r--r-- 3573700 r /
Mail 11824 6 173463 -rw-r--r-- 3573700 r /
Mail 11824 7 33271 -rw-r--r-- 740 r /
Mail 11824 8 132752 -rw-r--r-- 958464 rw /
Mail 11824 9 3612 -r--r--r-- 417 r /
Mail 11824 10 207213 -rw-r--r-- 25320 r /
Mail 11824 12* internet stream tcp 196ddb4
Mail 11824 13* unix dgram 1759c78 &lt;-&gt; 17598c0
Mail 11824 14* unix dgram 17598c0 &lt;-&gt; 1759c78
</font>

Any ideas? I'd like to figure out why Mail is frozen. And I'd rather not reboot.
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Jun 9, 2001, 09:35 PM
 
I've seen this happen in a handful of situations, and I have no idea what really causes it. I would be surprised if it was a bug in the original poster's code.

I've managed to cause it most reliably using "open -e &lt;filename&gt;" to open a file in TextEdit.app, especially when they're big files and especially when opening several files in succession. I've also seen it in a similar situation with one of my own tools (the openman command opening something in ManOpen.app). I've seen it happen once with Classic.app, and a Carbon newsreader too. Sometimes everything times out then goes back to normal, sometimes I can kill the guilty process (harder than you think if "ps" isn't working), and sometimes I have to reboot.

What seems to be happening is lookupd/NetInfo gets wedged -- if you let it time out (sometimes up to 15 minutes, sometimes never), you'll get errors in /var/tmp/console.log and/or /var/log/system.log, usually to the effect of "lookupd[&lt;pid&gt;]: NetInfo connection failed for server 127.0.0.1/local" and other errors. This is really bad, as many functions in the base C library go through lookupd to find information. In this case, it's most likely trying to find the username for a given uid (this is why ps and top hang, and I think you'll find that "ls -l" hangs too though just a simple "ls" works).

My only guess is that some hairy deadlock is going on in some mach messaging code. I've no idea if lookupd is the cause or if it's getting wedged by a deadlock caused by something else. I also have no idea what large amounts of text in an NSTextView would have to do with it, though that does seem to be a vaguely common thread here.

<font face = "courier">
Unable to attach to process-id 11824: Operation not permitted (1).
This request requires that the target process be neither setuid nor setgid and have the same real userid as the debugger, or that the debugger be running with adminstrator privileges.
</font>
Right, otherwise it would be a (large) security hole -- Mail.app is sgid to the "mail" group. gdb won't let you attach to a process that's running with more privileges than you have, since you're effectively able to completely control that process at that point. You can start Mail.app from gdb but it loses its sgid abilities at that point. I'm guessing that once you run as root it's getting past that problem and hitting the wedged NetInfo (most every app will hang if NetInfo is wedged).
     
Dedicated MacNNer
Join Date: Apr 2001
Location: San Francisco, USA
Status: Offline
Reply With Quote
Jun 9, 2001, 10:18 PM
 
I've encountered the netinfo bug you describe, but this Mail problem somehow seemed different. In the situation where netinfo gets 'wedged', the basic ps and ls commands work, but ps ax and ls -l options do not. However during my Mail freeze even a simple ps would fail. Oddly enough ls -l worked without a hitch. I was also able to continue browsing using OmniWeb (even though DNS is resolved through lookupd, IIRC).

     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:48 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2