How to Gently Kill Firefox Process on Linux/Os X

Firefox: Disable automatic safe mode after crash

I have no idea how you got this and what your testing flow is. So I can't reproduce and test the solution. But Firefox Safe Mode can be disabled by setting the key toolkit.startup.max_resumed_crashes in about:config to -1.

Here's how to start Firefox with that preference set in C# binding:

FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("toolkit.startup.max_resumed_crashes", "-1");

IWebDriver driver = new FirefoxDriver(profile);

How to get the process ID to kill a nohup process?

When using nohup and you put the task in the background, the background operator (&) will give you the PID at the command prompt. If your plan is to manually manage the process, you can save that PID and use it later to kill the process if needed, via kill PID or kill -9 PID (if you need to force kill). Alternatively, you can find the PID later on by ps -ef | grep "command name" and locate the PID from there. Note that nohup keyword/command itself does not appear in the ps output for the command in question.

If you use a script, you could do something like this in the script:

nohup my_command > my.log 2>&1 &
echo $! > save_pid.txt

This will run my_command saving all output into my.log (in a script, $! represents the PID of the last process executed). The 2 is the file descriptor for standard error (stderr) and 2>&1 tells the shell to route standard error output to the standard output (file descriptor 1). It requires &1 so that the shell knows it's a file descriptor in that context instead of just a file named 1. The 2>&1 is needed to capture any error messages that normally are written to standard error into our my.log file (which is coming from standard output). See I/O Redirection for more details on handling I/O redirection with the shell.

If the command sends output on a regular basis, you can check the output occasionally with tail my.log, or if you want to follow it "live" you can use tail -f my.log. Finally, if you need to kill the process, you can do it via:

kill -9 `cat save_pid.txt`
rm save_pid.txt

How to Close a program using python?

# I have used subprocess comands for a while
# this program will try to close a firefox window every ten secounds

import subprocess
import time

# creating a forever loop
while 1 :
subprocess.call("TASKKILL /F /IM firefox.exe", shell=True)
time.sleep(10)

Python: Using Ghost for dynamic webscraping

Note, I post this as answer since my current solution is to use the iMacros extension and save the webpage locally and then perform the scraping on the now static data using BeautifulSoup.

The original question was on how to use Ghost to work on the dynamic page but since I did not get so far I found another solution which can be of use for others.

The iMacro content(which I named GetWeather.iim):

VERSION BUILD=8881205 RECORDER=FX
TAB T=1
URL GOTO=http://www.metservice.com/maps-radar/local-observations/local-3-hourly-observations
WAIT SECONDS=5
SAVEAS TYPE=CPL FOLDER=* FILE=+_{{!NOW:yyyymmdd_hhnnss}}

shellscript called from crontab:

#!/bin/bash
export DISPLAY=:0.0
/usr/bin/firefox &
sleep 5
/usr/bin/firefox imacros://run/?m=GetWeather.iim
sleep 10
wmctrl -c "Mozilla Firefox"

together with a python script doing the actual web scraping using BeautifulSoup.

updated with proper way of stopping firefox without it to revert to safe mode as instructed in first answer to thread

Weak reference benefits

Soft and phantom references come from Java, I believe. A long weak reference (pass true to C#'s WeakReference constructor) might be considered similar to Java's PhantomReference. If there is an analog to SoftReference in C#, I don't know what it is.

Weak references do not extend the lifespan of an object, thus allowing it to be garbage collected once all strong references have gone out of scope. They can be useful for holding on to large objects that are expensive to initialize, but should be available for garbage collection if they are not actively in use.

Whether or not this will be useful in reducing the memory consumption of your application will depend completely on the specifics of the application. For example, if you have a moderate number of cached objects hanging around that may or may not be reused in the future, weak references could help improve the memory consumption of the caches. However, if the app is working with a very large number of small objects, weak references will make the problem worse since the reference objects will take up as much or more memory.



Related Topics



Leave a reply



Submit