Archives for: May 2011
Replace a word in multpile files
May 28th, 2011Using the feature "inplace edit" of perl to do it:
find /path/to/start/from/ -type f | xargs perl -pi.old -e 's/applicationX/applicationY/g'
Find in ruby
May 26th, 2011Find in ruby
Ruby has a module find which implement function as commnad "find".
Find.prune is used to stop recursive visit in following directory.
require 'find'
total_size = 0
Find.find(ENV["HOME"]) do |path|
if FileTest.directory?(path)
if File.basename(path)[0] == ?.
Find.prune # Don't look any further into this directory.
else
next
end
else
total_size += FileTest.size(path)
end
end
Cooperating with module such like File, using method like basename, extname, or Module FileTest, user can easy to implement find like functions.
Walk a directory/Recursively in Wikipedia
Wikipedia has a great page about work a directory recursively.
Shutdown or hibernate windows from command line
May 25th, 2011Download psshutdown from sysinternal.
psshutdown -h ---- hibernate system
ANR research in Android
May 25th, 2011ActivityManagerService
In frameworks/base/services/java/com/android/server/am/ActivityManagerService.java, serviceTimeout() is called when a service is timedout.
In this function, it will invoke appNotResponding() which calls dumpStackTrace() to dump all process stack into /data/anr/traces.txt.
Actually, dumpStackTrace() forces processes to dump their stacks by send SIG_QUIT(3).
By the way, if trace file name is not set, the ANR traces.file won't be created.
Detect ANR in service call
In function sendServiceArgsLocked() and other service related methods, first, it calls bumpServiceExecutingLocked(r, "start") which schdue a SERVCIE_TIMEOUT_MESSAGE in a furture time. So if service don't return inside SERVICE_TIMEOUT, ActivityManagerService would receive a SERVICE_TIMEOUT_MESSAGE and detect ANR.
Detect ANR in boradcast Receiver
Before send broadcast intent, setBroadcastTimeoutLocked()' is called which schedule aBROADCASTTIMEOUTMSGin the future. If this message is received, it means broadcast intent can't come back,appNotResponding()` is trigged in the last of call stack.
Detect ANR in InputService
If InputService can't get feedback in 5 seconds from user thread, it will call appNotResponding() to tigger ANR.
Bank Address
May 10th, 2011Name: Bank Of China Beijing Branch Address: SONGYULI SUB-BRANCH, NO.37 SONGYULI, BEIJING,CHINA
SWIFT CODE:BKCHCNBJ110