Macos – close a firefox tab through the console


There I was downloading a bunch of stuff from the Internet quite happily using Firefox built-in download manager when I decided to check code academy (a site that teaches you how to program in javascript, in a cool way – apparently).

So after playing with a few exercises I got to lesson 7 (item 4) which requires you to fill the conditions of a for loop to bring i (the loop variable) down to 0. What happened is that instead of writing the loop as for (i = 2; i >= 0; i--) which would trigger the inbuilt-mechanism that would take me to the next lesson, I "mistakenly" wrote is as for (i = 2; i >= 0; i++), making the loop go on forever causing Firefox to use 100% of the CPU, frizzing everything, and frustrating all my attempts to reload the page or close the tab.

Right now I have paused the process through kill -STOP <pid>, but I don't want to close Firefox because I'm downloading a bunch of stuff that can't be resumed, and I wonder if there's a way to close this tab through the command line. Maybe there's a way to list all firefox' threads and try to close them individually (worst case, I think GDB can assist me on this).

I'm currently using Mac OS X 10.7.2.

Best Answer

I did the same on Codecademy. Filled out something wrong and that resulted in an infinite loop, it seems like Codecademy isn't written to prevent such bad behavior so it gets elevated to the browser. In my case the browser just catches this and asks after a while to stop the script. I find it weird that this does not appear to be happening in your case, hence I would suggest you to upgrade Firefox after solving this so that this kind of condition can't occur again.

I'm afraid there is no way but finding a genious process management tool or attaching a debugger like gdb, this can become very tricky if you don't have any debugging information though. Just look for the thread that is somewhere in the Javascript execution routines. If you have no debug information and no dynamic libraries I guess it will be somewhere in which could be about any tab.

If you somehow figure out what the download thread is, you could attempt to freeze the other threads one by one to figure out which one is the actual tab. In the worst case freezing threads doesn't help, as the thread might be holding a lock that the other threads are waiting for. In that case you'd better just kill the process and start over with the downloads. Perhaps consider to huge downloads in a different way than with your browser, if possible...

Related Question