2008年2月19日星期二

俺用的ant批处理脚本

不想在环境变量里将%PATH%设置那么长,写了一个ant批处理脚本sean_ant.bat,放到%PATH%路径任一目录当中
@echo off
SETLOCAL
set JAVA_HOME=d:\shared\jdk1.5.0_12
set ANT_HOME=d:\shared\apache-ant-1.7.0
set PATH=%ANT_HOME%\bin;%JAVA_HOME%\bin;%PATH%
ant.bat %*

echo "Finished ant_sean compiling.  "
ENDLOCAL
执行sean_ant.bat -f build.xml <target>即可

Visual Studio C/C++ 编译器选项(Summary)

                          C/C++ 编译器选项
 
                              -优化-
 
/O1 最小化空间                          /Op[-] 改善浮点数一致性
/O2 最大化速度                          /Os 优选代码空间
/Oa 假设没有别名                        /Ot 优选代码速度
/Ob<n> 内联展开(默认 n=0)               /Ow 假设交叉函数别名
/Od 禁用优化(默认值)                    /Ox 最大化选项。(/Ogityb2 /Gs)
/Og 启用全局优化                        /Oy[-] 启用框架指针省略
/Oi 启用内部函数
 
                             -代码生成-
 
/G3 为 80386 进行优化                   /Gh 启用 _penter 函数调用
/G4 为 80486 进行优化                   /GH 启用 _pexit 函数调用
/G5 为 Pentium 进行优化                 /GR[-] 启用 C++ RTTI
/G6 对 PPro、P-II、P-III 进行优化       /GX[-] 启用 C++ EH (与 /EHsc 相同)
/G7 对 Pentium 4 或 Athlon 进行优化     /EHs 启用 C++ EH (没有 SEH 异常)
/GB 为混合模型进行优化(默认)            /EHa 启用 C++ EH(w/ SEH 异常)
/Gd __cdecl 调用约定                    /EHc extern "C" 默认为 nothrow
/Gr __fastcall 调用约定                 /GT 生成纤维安全 TLS 访问
/Gz __stdcall 调用约定                  /Gm[-] 启用最小重新生成
/GA 为 Windows 应用程序进行优化         /GL[-] 启用链接时代码生成
/Gf 启用字符串池                        /QIfdiv[-] 启用 Pentium FDIV 修复
/GF 启用只读字符串池                    /QI0f[-] 启用 Pentium 0x0f 修复
/Gy 分隔链接器函数                      /QIfist[-] 使用 FIST 而不是 ftol()
/GZ 启用堆栈检查(/RTCs)                 /RTC1 启用快速检查(/RTCsu)
/Ge 对所有函数强制堆栈检查              /RTCc 转换为较小的类型检查
/Gs[num] 控制堆栈检查调用               /RTCs 堆栈帧运行时检查
/GS 启用安全检查                        /RTCu 未初始化的本地用法检查
/clr[:noAssembly] 为公共语言运行库编译
    noAssembly - 不产生程序集
/arch:<SSE|SSE2> CPU 结构的最低要求,以下内容之一:
    SSE - 启用支持 SSE 的 CPU 可用的指令
    SSE2 - 启用支持 SSE2 的 CPU 可用的指令
 
                              -输出文件-
 
/Fa[file] 命名程序集列表文件            /Fo<file> 命名对象文件
/FA[sc] 配置程序集列表                  /Fp<file> 命名预编译头文件
/Fd[file] 命名 .PDB 文件                /Fr[file] 命名源浏览器文件
/Fe<file> 命名可执行文件                /FR[file] 命名扩展 .SBR 文件
/Fm[file] 命名映射文件
 
                              -预处理器-
 
/AI<dir> 添加到程序集搜索路径           /Fx 将插入的代码合并到文件
/FU<file> 强制使用程序集/模块           /FI<file> 命名强制包含文件
/C 不抽出注释                           /U<name> 移除预定义宏
/D<name>{=|#}<text> 定义宏              /u 移除所有预定义宏
/E 预处理到 stdout                      /I<dir> 添加到包含搜索路径
/EP 预处理到 stdout,没有 #line         /X 忽略"标准位置"
/P 预处理到文件
 
                                -语言-
 
/Zi 启用调试信息                        /Ze 启用扩展(默认)
/ZI 启用"编辑并继续"调试信息          /Zl 省略 .OBJ 中的默认库名
/Z7 启用旧式调试信息                    /Zg 生成函数原型
/Zd 仅有行号调试信息                    /Zs 只进行语法检查
/Zp[n] 在 n 字节边界上包装结构          /vd{0|1} 禁用/启用 vtordisp
/Za 禁用扩展(暗指 /Op)                  /vm<x> 指向成员的指针类型
/Zc:arg1[,arg2] C++ 语言一致性,这里的参数可以是:
    forScope - 对范围规则强制使用标准 C++
    wchar_t - wchar_t 是本机类型,不是 typedef
 
                              - 杂项 -
 
@<file> 选项响应文件                    /wo<n> 发出一次警告 n
/?, /help 打印此帮助消息                /w<l><n> 为 n 设置警告等级 1-4
/c 只编译,不链接                       /W<n> 设置警告等级(默认 n=1)
/H<num> 最大外部名称长度                /Wall 启用所有警告
/J 默认 char 类型是 unsigned            /Wp64 启用 64 位端口定位警告
/nologo 取消显示版权消息                /WX 将警告视为错误
/showIncludes 显示包含文件名            /WL 启用单行诊断
/Tc<source file> 将文件编译为 .c        /Yc[file] 创建 .PCH 文件
/Tp<source file> 将文件编译为 .cpp      /Yd 将调试信息放在每个 .OBJ 中
/TC 将所有文件编译为 .c                 /Yl[sym] 为调试库插入 .PCH 引用
/TP 将所有文件编译为 .cpp               /Yu[file] 使用 .PCH 文件
/V<string> 设置版本字符串               /YX[file] 自动 .PCH
/w 禁用所有警告                         /Y- 禁用所有 PCH 选项
/wd<n> 禁用警告 n                       /Zm<n> 最大内存分配(默认为 %)
/we<n> 将警告 n 视为错误
 
                                 -链接-
 
/MD 与 MSVCRT.LIB 链接                  /MDd 与 MSVCRTD.LIB 调试库链接
/ML 与 LIBC.LIB 链接                    /MLd 与 LIBCD.LIB 调试库链接
/MT 与 LIBCMT.LIB 链接                  /MTd 与 LIBCMTD.LIB 调试库链接
/LD 创建 .DLL                           /F<num> 设置堆栈大小
/LDd 创建 .DLL 调试库                   /link [链接器选项和库]

JVM specification Notes(1)

jvm 规范:
jvm是一个抽象机。与具体实现没有直接联系。
jvm支持两种数据类型:原生类型以及引用类型
floating-point,参考ieee754标准."NaN" - Not a Number.
boolean型,包括关系操作以及逻辑操作.它与其它原生类型不存在直接转换
引用类型:有三种,class类型,接口类型,以及数组类型,对象是动态创建的类或数组实例.
类实例创建的两个途径:newInstance通过Class,或通过class实例的创建表达式
对象在heap中创建,在没有针对它的引用时,被垃圾回收。对象占用的空莘不能通过显示的语言调用进行回收。
任何一个对某对象的引用,进而改变该对象,新的状态会让所有引用该对象的引用看到.
每个对象都有一个相联锁(associated lock),使用synchronized methods来表示,或者synchronized语句.
引用类型形成一个层次结构. Object类型可以拥有任意对象的引用(类实例或者数组的实例)
变量类型:
 类变量, 在class声明里采用static关键字,或在interface声明里可不带static关键字.这种类型变量在类或接口装载的时候就被初始化为默认值,当类unload时,这些变量自然会exit.
 实例变量,在class声明当中,不带关键字static,如果class T有一个实例变量a,则a会在每个T类型或其子类新创建的T实例中创建,当它所对应的对象不再被引用,在所有必要的终结操作完成以后,它就会退出生命期。
 Array,未使名变量,无论新对象何时创建,初始化时都带有默认值。当它不再被引用时,则生命期结束。
 传递给方法的参数变量值,对方法声明中的每个参数,新的参数变量会在方法调用的时候创建. 当方法体结束时,参数变量生命期结束。
 构造函数参数,与方法参数变量雷同
 异常句柄参数变量,在catch块结束时,生命期结束
 局部变量,只有在它被执行的时候才被初始化.
变量的初始化值:
 class, 实例变量,array,初始化成它创建时候的默认值 
 byte, short, int, long(0L), float(0.0f), double(0.0.), char('\0000')
 boolean(false)
 reference type: null
 method parameter, 与对应的参数类型一致
 local变量,在使用之前,必须显示地给定一个值或者初始化或者赋值.
    type是一个编译期概念,而变量或者表达式都有自己的type,对象或数组没有type,但是拥有自己的class.
    每个array都有自己的class, array的class名字比较奇怪,并且不是合法的标识,一个int数组,名字为"[I".
    jvm退出:在下面两个条件之一成立时
 所有非daemon线程终结时
 某些线程调用Runtime或者System的exit方法,并且exit被security manager允许时.
        当然,可以调用System的runFinalizersOnExit(true)方法强制在exit之前执行所有 class的 finalize方法.默认情况下,是不会调用的.
chapter 3.
    类型和值的返回地址, returnAddress由jsr, ret, jsr_w指令使用.指向jvm指令的opcode的指针.
    boolean,没有专门的类型来处理,直接使用int来代替,而对boolean数组,则使用指令baload和bastore来处理.jvm使用1表示true, 0表示false.
    reference type.
    运行时数据区,3.5.1(***)

Out of memory systems that use many threads java(Summary)

I recently came across this exception on a couple of java systems that use many threads  java.lang.OutOfMemoryError: unable to create new native thread. The strange thing was that the JVM had been assigned a lot of memory (1.5GB) and that it had at least half the memory available. Michele found this article that points out that the more memory you give to the JVM the more likely you are to get java.lang.OutOfMemoryError: unable to create new native thread exceptions when you have many threads.

Which makes perfect sense when you think about it. Each 32 bit process on Windows has 2GB "available" memory as 2GB is reserved to Windows. In my case the JVM grabbed 1.5 GB leaving 500MB. Part of the 500MB was used to map system dlls etc in memory so less than 400 MB was left. Now to the crucial point: When you create a thread in java it creates a Thread object in the JVM memory but it also creates a operating system thread. The operating system creates the thread with a thread stack in the 400MB that is left, not in the 1.5 GB allocated in the JVM. Java 1.4 uses a default stack size of 256kb but Java 1.5 uses a 1MB stack per thread. So, in the 400MB left to process I could only generate ~400 threads. Absurd but true: to create more threads you have to reduce the memory allocated to the JVM. Another option is to host the JVM in your own process using JNI.

This formula gives a decent estimate for the number of threads you can create:
(MaxProcessMemory - JVMMemory - ReservedOsMemory) / (ThreadStackSize) = Number of threads

For Java 1.5 I get the following results assuming that the OS reserves about 120MB:
1.5GB allocated to JVM: (2GB-1.5Gb-120MB)/(1MB) = ~380 threads
1.0GB allocated to JVM: (2GB-1.0Gb-120MB)/(1MB) = ~880 threads

Java 1.4 uses 256kb for the thread stack which lets you create a lot more threads:
1.5GB allocated to JVM: ~1520 threads
1.0GB allocated to JVM: ~3520 threads

I have not tried the 3GB switch but it should in theory let you create more threads.

crontab使用简记

Crontab - Quick reference

Setting up cronjobs in Unix and Solaris

cron is a unix, solaris utility that allows tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in unix , solaris.

Crontab (CRON TABle) is a file which contains the schedule of cron entries to be run and at specified times.

 

Following points sum up the crontab functionality :

1. Crontab Restrictions

2. Crontab Commands

3. Crontab file - syntax

4. Crontab Example

5. Crontab Environment

6. Disable Email

7. Generate log file for crontab activity

8. Next Steps

 

1. Crontab Restrictions

____________

You can execute crontab if your name appears in the file /usr/lib/cron/cron.allow. If that file does not exist, you can use

crontab if your name does not appear in the file /usr/lib/cron/cron.deny.

If only cron.deny exists and is empty, all users can use crontab. If neither file exists, only the root user can use crontab. The allow/deny files consist of one user name per line.

 

 

2. Crontab Commands

__________

export EDITOR=vi ;to specify a editor to open crontab file.

 

crontab -e     Edit your crontab file, or create one if it doesn't already exist.

crontab -l      Display your crontab file.

crontab -r      Remove your crontab file.

crontab -v      Display the last time you edited your crontab file. (This option is only available on a few systems.)

 

 

3. Crontab file

___________

Crontab syntax :-

A crontab file has five fields for specifying day , date and time  followed by the command to be run at that interval.*     *   *   *    *  command to be executed

-     -    -    -    -

|     |     |     |     |

|     |     |     |     +----- day of week (0 - 6) (Sunday=0)

|     |     |     +------- month (1 - 12)

|     |     +--------- day of month (1 - 31)

|     +----------- hour (0 - 23)

+------------- min (0 - 59)

 

 

 

* in the value field above means all legal values as in braces for that column.

The value column can have a * or a list of elements separated by commas. An element is either a number in the ranges shown above or two numbers in the range separated by a hyphen (meaning an inclusive range).

 

Note: The specification of days can be made in two fields: month day and weekday. If both are specified in an entry, they are cumulative meaning both of the entries will get executed .

 

4. Crontab Example

_______

 

A line in crontab file like below  removes the tmp files from /home/someuser/tmp each day at 6:30 PM.

 

30     18     *     *     *         rm /home/someuser/tmp/*

 

 

 

Changing the parameter values as below will cause this command to run at different time schedule below :min     hour            day/month        month   day/week         Execution time

30        0          1          1,6,12  *          -- 00:30 Hrs  on 1st of Jan, June & Dec.

 

:

0          20        *          10        1-5       --8.00 PM every weekday (Mon-Fri) only in Oct.

 

:

0          0          1,10,15            *          *          -- midnight on 1st ,10th & 15th of month

 

:

5,10     0          10        *          1          -- At 12.05,12.10 every Monday & on 10th of every month

:

 

 

Note : If you inadvertently enter the crontab command with no argument(s), do not attempt to get out with Control-d. This removes all entries in your crontab file. Instead, exit with Control-c.

 

5. Crontab Environment

___________

cron invokes the command from the user's HOME directory with the shell, (/usr/bin/sh).

cron supplies a default environment for every shell, defining:

HOME=user's-home-directory

LOGNAME=user's-login-id

PATH=/usr/bin:/usr/sbin:.

SHELL=/usr/bin/sh

 

Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry.

 

6. Disable Email

____________

 

By default cron jobs sends a email to the user account executing the cronjob. If this is not needed put the following command At the end of the cron job line .

 

>/dev/null 2>&1

 

7. Generate log file

________________

 

To collect the cron execution execution log in a file :

 

30 18  *    *   *    rm /home/someuser/tmp/* > /home/someuser/cronlogs/clean_tmp_dir.log

8. Next Steps

 

This  article  covered  a significant aspect of system administration of setting up cronjobs . Unix administration involves lots of different tasks and some of these tasks are covered in this website  but still there are many areas not covered here .

 

Following books available for online buying from Amazon.com . You should have following two books in your bookshelf  for ready reference  if you are involved in Unix system administration  .

发现XP当中一个有用的命令,用于删除和查询系统中的服务名

输入命令SC:
DESCRIPTION:
        SC is a command line program used for communicating with the
        NT Service Controller and services.
USAGE:
        sc <server> [command] [service name] <option1> <option2>...
 
        The option <server> has the form "\\ServerName"
        Further help on commands can be obtained by typing: "sc [command]"
        Commands:
          query-----------Queries the status for a service, or
                          enumerates the status for types of services.
          queryex---------Queries the extended status for a service, or
                          enumerates the status for types of services.
          start-----------Starts a service.
          pause-----------Sends a PAUSE control request to a service.
          interrogate-----Sends an INTERROGATE control request to a service.
          continue--------Sends a CONTINUE control request to a service.
          stop------------Sends a STOP request to a service.
          config----------Changes the configuration of a service (persistant).
          description-----Changes the description of a service.
          failure---------Changes the actions taken by a service upon failure.
          qc--------------Queries the configuration information for a service.
          qdescription----Queries the description for a service.
          qfailure--------Queries the actions taken by a service upon failure.
          delete----------Deletes a service (from the registry).
          create----------Creates a service. (adds it to the registry).
          control---------Sends a control to a service.
          sdshow----------Displays a service's security descriptor.
          sdset-----------Sets a service's security descriptor.
          GetDisplayName--Gets the DisplayName for a service.
          GetKeyName------Gets the ServiceKeyName for a service.
          EnumDepend------Enumerates Service Dependencies.
 
        The following commands don't require a service name:
        sc <server> <command> <option>
          boot------------(ok | bad) Indicates whether the last boot should
                          be saved as the last-known-good boot configuration
          Lock------------Locks the Service Database
          QueryLock-------Queries the LockStatus for the SCManager Database
EXAMPLE:
        sc start MyService

应用python-sybase访问ASE数据库(一)

Python2.5提供了标准的PEP 249 -- Python Database API Specification v2.0,可以使用基本一致的接口来访问各种类型的数据库,对应于ASE数据库,则有开源的python-sybase实现了该接口,从Web站点http://python-sybase.sourceforge.net上可以下载到该模块。

1.1       安装python-sybase模块

首先,确保系统中已经安装好了Python,并且也安装了Sybase ASE客户端,它带有OpenClient,从环境变量%SYBASE%以及%SYBASE_OCS%可以判断得到(linux/unix下是$SYBASE$SYBASE_OCS)

另外,由于安装过程需要对其中的C程序进行编译和链接,Windows平台需要拥有Microsoft Visual Studio .NET 2003\Vc7来进行编译。

http://downloads.sourceforge.net/python-sybase/python-sybase-0.38.tar.gz下载到python-sybase的模块压缩包,将其解压至目录:python-sybase-0.38,发现其目录结构如下:

E:\LEARN\PYTHON\REF\PYTHON-SYBASE-0.38

├─build

  ├─lib.win32-2.5

  └─temp.win32-2.5

      └─Release

├─doc

├─*.c, *.py, *.h

└─examples

一般情况下,直接运行python setup.py install,直接就完成了python-sybase模块的安装,实际情况,可能有些不太一样,从它的网站上的平台支持列表,我们可以看到,目前在Windows平台上,似乎不支持Openclient15.0.x

10-1 python-sybase支持平台及ASE版本

Client

Server

OS

Libraries

OS

Libraries

Linux

Sybase ASE 15.0.1 (32bits)

Linux

Sybase ASE 15.0.1

Linux 64-bits

OpenClient 12.5

Linux

Sybase ASE 12.5

Linux

Sybase ASE 12.5 (32bits)

Linux

Sybase ASE 12.5

Linux

Sybase ASE 11.9.2

Linux

Sybase ASE 11.9.2

Linux

Sybase ASE 11.0.3

Linux

Sybase ASE 11.0.3

Linux

FreeTDS

Linux

Sybase ASA 9.0.2

Mac OS X 10.4.x

FreeTDS 0.62

Linux

Sybase ASE 12.5

Windows 2000 Prof SP1

Sybase ASE 11.9.2

Windows NT 4.0

Sybase ASE 11.9.2

Windows NT 4.0 SP6

Sybase ASE 11.9.2

HPUX 10.20

Sybase ASE 11.9.2

Windows 98

Sybase ASE 11.9.2

NT 4.0 SP6

OpenClient 11.5

Windows 95 OSR2

Sybase ASE 11.9.2

Solaris 2.6

OpenClient 11.5

Solaris 10

Sybase ASE 15.0.1 (32bits)

Solaris 10

Sybase ASE 15.0.1

Solaris 10

Sybase ASE 12.5 (32bits)

Solaris 10

Sybase ASE 12.5

Solaris 8

Sybase ASE 15.0.1 (32bits)

Solaris 8

Sybase ASE 15.0.1

Solaris 8

Sybase ASE 12.5 (32bits)

Solaris 8

Sybase ASE 12.5

SunOS 5.9

OpenClient 12.0

SunOS 5.9

Sybase ASE 12.5

Solaris 2.6

Sybase ASE 11.5.1

Solaris 8

OpenClient 11.5

Solaris 5.6

Sybase ASE 11.0.3

 

 

AIX 5.3

Sybase ASE 15.0.1 (32bits)

AIX 5.3

Sybase ASE 15.0.1

AIX 5.2

Sybase ASE 12.5 (32bits)

AIX 5.2

Sybase ASE 12.5.1

IRIX 6.5

11.5.1

 

 

HP-UX 11

11.5.1

 

 

 

要支持Sybase ASE15.0及以上版本,需要手动修改setup.py中的有关代码。

我们从中找到下面的代码块:

elif os.name == 'nt':                   # win32

    # Not sure how the installation location is specified under NT

    if sybase is None:

        sybase = r'i:\sybase\sql11.5'

        if not os.access(sybase, os.F_OK):

            sys.stderr.write(

                'Please define the Sybase installation directory in'

                'the SYBASE environment variable.\n')

            sys.exit(1)

    syb_libs = ['libblk', 'libct', 'libcs']

   

将其中的syb_libs = ['libblk', 'libct', 'libcs']替换为syb_libs = ['libsybblk', 'libsybct', 'libsybcs']即可。原因是在ASE15.0及以上版本,这三个动态库的名字都发生了变化。我在Sybase ASE15.0下安装这个包时发现了此问题。15.0以下版本,无需修改该文件就可以安装。

安装的命令是:python setup.py install

安装完以后,在python目录下边,我们会发现有下述安装好的文件:

Lib\site-packages\Sybase.py

Lib\site-packages\python_sybase-0.38-py2.5.egg-info

Lib\site-packages\sybasect.pyd