Wednesday, July 11, 2007

Mac上的Terminal

Unix Terminal Emulators

There are two levels of Chinese support that must be addressed. The first is in the Unix terminal emulation software, which needs to be set up to emulate a localized Chinese Unix terminal in order to handle double-byte Chinese character set encodings (as opposed to handling Chinese with Unicode). See the entries below for some details.

The second level is in the Unix operating system. The shell environment variables have to be set to the corresponding Chinese locale (when connecting to a localized Chinese server, for example). You can either type in the commands manually at the command line or add them to your ~/.cshrc file. Both terminal emulators start up with the default shell (tcsh, for example). When tcsh starts, it looks for and reads a number of initialization files. One of those files is ~/.cshrc. Placing setenv commands in the ~/.cshrc file ensures that the locale is set at startup and saves you the trouble of manually typing the commands every time.

Commands for the tcsh shell and Traditional Chinese locale (Big Five character set):

setenv LC_CTYPE zh_TW.Big5
setenv LANG zh_TW.Big5

Commands for the tcsh shell and Simplified Chinese locale (GB 2312 character set):

setenv LC_CTYPE zh_CN.EUC
setenv LANG zh_CN.EUC

To upload or download files containing Chinese, you must set the FTP transfer mode to binary format before you enter the get or put commands.

Apple Terminal

OS X only, in the /Applications/Utilities folder. This discussion is based on Terminal 1.4.1 in OS X 10.3.

UTF-8 is the default setting, and you can enter Unicode Chinese characters using the Character Palette without changing any settings. Other standard Chinese character set encodings are available in Terminal > Window Settings... Display, and thus Terminal shell windows can be set up to emulate localized Chinese Unix terminals.

iTerm

OS X only. iTerm is an open-source project focused on multilingual support, including Unicode and all standard East Asian encodings. Change the encoding in Preferences > Shell settings to set up iTerm to emulate a localized Chinese Unix terminal.

http://iterm.sourceforge.net/

以上来自http://www.yale.edu/chinesemac/pages/internet.html

其他资料:

http://tristan.ethereal.net/osx/terminal.html

http://apple.slashdot.org/article.pl?sid=03/06/09/1754234

http://www.rift.dk/news.php?item.7.6

Monday, July 2, 2007

Mac OS X 最大进程数默认为100

有时候会出现"fork: Resource temporarily unavailable" 或者 "tcsh: no more processes" 的错误,是因为进程数达到最大值了。

运行%launchctl limit,输出:

        cpu         unlimited      unlimited      
        filesize    unlimited      unlimited      
        data        6291456        unlimited      
        stack       8388608        67108864       
        core        0              unlimited      
        rss         unlimited      unlimited      
        memlock     unlimited      unlimited      
        maxproc     100            532            
        maxfiles    256            unlimited     

To change this you need to create /etc/launchd.conf file if it does not already exist and add the following line:

limit maxproc 512 2048

The first number is the soft limit and the second number is the hard limit. You can pick different values if you want.




按任务名称kill系列进程

A method for killing a process from the command line: using a variation on a script in this writeup. The secret is using the -o flag to control the output of ps. You can then use awk and grep as usual, and xargs to cycle through the results and kill all matching processes. Consider this command:
ps axco pid,command
That will output only the process ID and the command name, which makes for easy pickings for a script to find and kill! I changed the original script from the command ps e to ps axc -- -a, -x, and other flags will vary depending on the user's needs. However, do not invoke the script with the -u (e.g. ps aux ), which is the way that it is normally suggested to run the ps command. The -u flag specifies the format, and overides the -o flag.

Example: to add this to a script to kill the Finder you wold do:
ps axco pid,command | grep Finder | awk '{ print $1; }' | xargs kill -9
The original article explains how to variablize it, so you could set up a generic script and run it on multiple platforms with different versions of ps by invoking:
script_name $SIG $PROCESSNAME
Remember! This script kills all processes that are named $PROCESSNAME, so it's a good idea to use ps -c, which just prints the executable name, instead of the full path. That way it won't accidently kill another process that maches a folder or something else.

There are some other tricks for using ps in that writeup as well...