﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-GCC/GNU/Linux Delphi/Window Java/Anywhere</title><link>http://www.cppblog.com/Khan/</link><description>路漫漫，长修远，我们不能没有钱</description><language>zh-cn</language><lastBuildDate>Sun, 05 Jul 2009 22:03:13 GMT</lastBuildDate><pubDate>Sun, 05 Jul 2009 22:03:13 GMT</pubDate><ttl>60</ttl><item><title>NO.7 信令系统基本功能结构</title><link>http://www.cppblog.com/Khan/archive/2009/07/01/88998.html</link><dc:creator>Khan's Notebook</dc:creator><author>Khan's Notebook</author><pubDate>Wed, 01 Jul 2009 08:16:00 GMT</pubDate><guid>http://www.cppblog.com/Khan/archive/2009/07/01/88998.html</guid><wfw:comment>http://www.cppblog.com/Khan/comments/88998.html</wfw:comment><comments>http://www.cppblog.com/Khan/archive/2009/07/01/88998.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Khan/comments/commentRss/88998.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Khan/services/trackbacks/88998.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: No.7  SS7&nbsp;&nbsp;<a href='http://www.cppblog.com/Khan/archive/2009/07/01/88998.html'>阅读全文</a><img src ="http://www.cppblog.com/Khan/aggbug/88998.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Khan/" target="_blank">Khan's Notebook</a> 2009-07-01 16:16 <a href="http://www.cppblog.com/Khan/archive/2009/07/01/88998.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>7bit_default_table pud格式7bit编码对应表</title><link>http://www.cppblog.com/Khan/archive/2009/05/08/82240.html</link><dc:creator>Khan's Notebook</dc:creator><author>Khan's Notebook</author><pubDate>Fri, 08 May 2009 07:45:00 GMT</pubDate><guid>http://www.cppblog.com/Khan/archive/2009/05/08/82240.html</guid><wfw:comment>http://www.cppblog.com/Khan/comments/82240.html</wfw:comment><comments>http://www.cppblog.com/Khan/archive/2009/05/08/82240.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/Khan/comments/commentRss/82240.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Khan/services/trackbacks/82240.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp; &nbsp;GSM 3.38中定义的pdu格式编码, 其中7bit的部分不光要处理常见的ascii编码, 还要处理一些欧洲字符, 这些字符不在常规的127个ascii字符中, 所以需要如下映射表做一个映射, 另有部分字符与在ascii中的位置不一致, 所以千万要注意. 网上不少山寨代码都忽略协议. 想当然的实现了所谓的pdu编码格式. 忧郁中.    &nbsp;...&nbsp;&nbsp;<a href='http://www.cppblog.com/Khan/archive/2009/05/08/82240.html'>阅读全文</a><img src ="http://www.cppblog.com/Khan/aggbug/82240.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Khan/" target="_blank">Khan's Notebook</a> 2009-05-08 15:45 <a href="http://www.cppblog.com/Khan/archive/2009/05/08/82240.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Blackberry JDE 4.5中文开发环境设置</title><link>http://www.cppblog.com/Khan/archive/2009/02/12/73574.html</link><dc:creator>Khan's Notebook</dc:creator><author>Khan's Notebook</author><pubDate>Thu, 12 Feb 2009 07:28:00 GMT</pubDate><guid>http://www.cppblog.com/Khan/archive/2009/02/12/73574.html</guid><wfw:comment>http://www.cppblog.com/Khan/comments/73574.html</wfw:comment><comments>http://www.cppblog.com/Khan/archive/2009/02/12/73574.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/Khan/comments/commentRss/73574.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Khan/services/trackbacks/73574.html</trackback:ping><description><![CDATA[以8820为例:<br>8820的操作系统为4.5版本, 所以需要下载 JDE 4.5 包含ide和sdk 以及对应的模拟器<br><br>1.下载安装 Blackberry JDE 4.5.0.exe<br><br><br>2. 在 安装目录\Research In Motion\BlackBerry JDE 4.5.0\simulator\Java下<br>编辑 chinese.bat<br>输入<br>javaloader&nbsp; -usb load&nbsp; net_rim_vad_resource__zh_CN.cod net_rim_vad_engine_resource__zh_CN.cod net_rim_bb_crypto_resource__zh_CN.cod net_rim_bb_options_chinese.cod net_rim_bb_resource__zh_CN.cod&nbsp; net_rim_font_chinese.cod&nbsp; net_rim_font_chinese_hong_kong.cod&nbsp; net_rim_platform_im_resource__zh_CN.cod&nbsp; net_rim_platform_resource__zh.cod&nbsp; net_rim_platform_resource__zh_CN.cod&nbsp; net_rim_platform_resource__zh_HK.cod&nbsp; net_rim_platformapps_resource__zh_CN.cod net_rim_runtime_resource__zh_CN.cod&nbsp; net_rim_secureemail_resource__zh_CN.cod&nbsp; net_rim_tid_chinese_cj_core.cod&nbsp; net_rim_tid_chinese_jni_core.cod&nbsp; net_rim_tid_dynamic_transcoding_data_Big5_HKSCS.cod&nbsp; net_rim_tid_dynamic_transcoding_data_EUC_CN.cod&nbsp; <br><br>保存退出<br><br><br>3.copy 安装目录\Research In Motion\BlackBerry JDE 4.5.0\bin\JavaLoader.exe 到安装目录\Research In Motion\BlackBerry JDE 4.5.0\simulator\Java下<br><br>开启模拟器<br>选中菜单Simulate-&gt;USB cable connect <br><br>4.执行chinese.bat,然后退出模拟器<br><br>5.在 安装目录\Research In Motion\BlackBerry JDE 4.5.0\simulator\Java下<br>编辑 chineseinput.bat<br>输入<br>javaloader&nbsp; -usb load&nbsp; net_rim_tid_chinese_PinyinForReduced.cod net_rim_bb_options_PinyinFR.cod net_rim_tid_chinese_wubi.cod net_rim_platform_resource__zh_CN_WuBiHua.cod net_rim_platform_resource__zh_TW.cod net_rim_tid_chinese_stroke_trad.cod net_rim_platform_resource__zh_TW_Strokes.cod net_rim_platform_resource__zh_HK_Strokes.cod net_rim_font_chinese_hong_kong.cod net_rim_tid_dynamic_transcoding_data_Big5_HKSCS.cod net_rim_font_japanese.cod net_rim_tid_dynamic_transcoding_data_Shift_JIS.cod net_rim_tid_dynamic_transcoding_data_EUC_JP.cod net_rim_font_korean.cod net_rim_tid_dynamic_transcoding_data_EUC_KR.cod net_rim_tid_dynamic_transcoding_data_x_Johab.cod net_rim_tid_dynamic_transcoding_data_KSC5601.cod net_rim_bb_options_chinese.cod net_rim_tid_chinese_common.cod net_rim_tid_chinese_jni_core.cod net_rim_tid_chinese_cj_core.cod net_rim_platform_im_resource__zh_CN.cod net_rim_platform_resource__zh_CN.cod net_rim_platformapps_resource__zh_CN.cod net_rim_platform_resource__zh_HK.cod net_rim_platform_resource__zh.cod net_rim_font_chinese.cod net_rim_tid_dynamic_transcoding_data_EUC_CN.cod net_rim_font_chinese_traditional.cod net_rim_tid_dynamic_transcoding_data_Big5.cod net_rim_font_chinese_hong_kong.cod net_rim_tid_dynamic_transcoding_data_Big5_HKSCS.cod net_rim_runtime_resource__zh_CN.cod net_rim_bb_resource__zh_CN.cod net_rim_bb_diagnostic_resource__zh.cod net_rim_bb_diagnostic_resource__zh_CN.cod net_rim_runtime_resource__zh_TW.cod net_rim_bb_resource__zh_TW.cod net_rim_bb_diagnostic_resource__zh.cod net_rim_bb_diagnostic_resource__zh_TW.cod net_rim_tid_dynamic_ling_data_chinese_Wubizixing_wordlist.cod net_rim_tid_dynamic_ling_data_chinese_CN_wordlist.cod net_rim_tid_dynamic_ling_data_chinese_TW_CangJei_wordlist.cod net_rim_platform_resource__zh_CN_Pinyin.cod<br><br>保存退出<br><br><br>开启模拟器<br>选中菜单Simulate-&gt;USB cable connect <br><br>6.执行chineseinput.bat, 然后退出模拟器<br><br>7.打开8820模拟器, 进入模拟器中的设置向导进行设置, 包括中文, 中文输入<br><br>我写了个hello world 中文菜单显示正常<br><br>8.设置模拟器的sd卡使用pc文件系统<br>打开JDE--&gt;EDIT--&gt;Preferences..--&gt;Simulator--&gt;Memory<br>勾选Use PC filesystem for SD card files<br>在 SD Card Image 中填写你的指定目录<br>则模拟器中的sd卡会mount你选中的目录<br>  <img src ="http://www.cppblog.com/Khan/aggbug/73574.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Khan/" target="_blank">Khan's Notebook</a> 2009-02-12 15:28 <a href="http://www.cppblog.com/Khan/archive/2009/02/12/73574.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux 进程互斥锁</title><link>http://www.cppblog.com/Khan/archive/2008/12/24/70218.html</link><dc:creator>Khan's Notebook</dc:creator><author>Khan's Notebook</author><pubDate>Wed, 24 Dec 2008 02:45:00 GMT</pubDate><guid>http://www.cppblog.com/Khan/archive/2008/12/24/70218.html</guid><wfw:comment>http://www.cppblog.com/Khan/comments/70218.html</wfw:comment><comments>http://www.cppblog.com/Khan/archive/2008/12/24/70218.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/Khan/comments/commentRss/70218.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Khan/services/trackbacks/70218.html</trackback:ping><description><![CDATA[&nbsp;&nbsp; 最开始打算用semaphore实现, <br><br>sem_t waitNonEmpty;<br>int empty=0;&nbsp; <br>sem_init(&amp;waitNonEmpty, 1, empty); /*初始化信号量*/<br><br>sem_wait(&amp;waitNonEmpty);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*是否有"非空资源"*/<br>sem_post(&amp;waitNonEmpty);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*生成一个"非满资源"*/<br>sem_destroy(&amp;waitNonEmpty);<br><br>后来在fc3 redhat7.3下man了sem_init, 第二个参数int pshared <br>The pshared<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; argument indicates whether the semaphore is local to the&nbsp; current&nbsp; pro-<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cess&nbsp; ( pshared is zero) or is to be shared between several processes (<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pshared is not zero). LinuxThreads currently does not support&nbsp; process-<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shared&nbsp; semaphores,&nbsp; thus&nbsp; sem_init always returns with error ENOSYS if<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pshared is not zero.<br><br>最邪恶的现状出来了, 这俩系统没有实现sem的进程间通信, 如果设置not zero, 会返回ENOSYS的错误...<br>后来找了个redhat Enterprise 4 看了下文档, 貌似又支持了....<br><br>做个记号. 一会儿看看flock<br>fcntl 是唯一符合posix的文件锁<br>
<p><span style="color: #0000ff;">结构体flock的指针</span>
<span style="color: #000000;">：</span>
</p>
<p>struct flcok { <br>&nbsp; short int l_type; /* 锁定的状态*/</p>
<p>&nbsp; //这三个参数用于分段对文件加锁，若对整个文件加锁，则：l_whence=SEEK_SET,l_start=0,l_len=0;<br>&nbsp; short int l_whence;/*决定l_start位置*/ <br>&nbsp; off_t l_start; /*锁定区域的开头位置*/ <br>&nbsp; off_t l_len; /*锁定区域的大小*/<br><br>&nbsp; pid_t l_pid; /*锁定动作的进程*/ <br>
};</p>
<p><br>
l_type 有三种状态: <br>
F_RDLCK 建立一个供读取用的锁定 <br>
F_WRLCK 建立一个供写入用的锁定 <br>
F_UNLCK 删除之前建立的锁定</p>
<br>int fcntl(int fd, int cmd, struct flock *lock);<br>int cmd<br>&nbsp; //F_SETLKW对加锁操作进行阻塞，<br>&nbsp; //F_SETLK不对加锁操作进行阻塞，立即返回<br><br>&nbsp;&nbsp;&nbsp; 当使用F_SETLK宏，不进行阻塞加锁操作时。两个进程有对文件加锁失败的情况出现。<br>&nbsp;&nbsp;&nbsp; 当使用F_SETLKW宏，进行阻塞加锁操作时。两个进程没有文件加锁失败的情况。但是根据进程的输出日志，可以明显看出A进程对文件操作时，B进程停止对文件操作。<br>&nbsp;&nbsp;&nbsp; 测试过程中打开文件使用O_RDWR | O_CREAT | O_APPEND模式，并对文件加写锁。锁对打开文件没有影响，但是对另一进程加锁和写操作有影响。<br>&nbsp; 加锁对同一进程中的多线程无效。同一进程中的多线程对同一文件加锁，后加锁的线程会覆盖前一个线程加的文件锁。<br>&nbsp; fcntl文档中写到，一个进程对一个文件的区域只能加一个类型的锁<br><br><br><br>实现代码如下:<br>//filelock.h<br>#ifndef __FILE_LOCK_HPP__
<br>#define __FILE_LOCK_HPP__<br><br>&nbsp;<br>#ifdef __cplusplus<br>extern "C" {<br>#endif<br><br>&nbsp;<br>int file_lock(int fd);
<br>int file_unlock(int fd);<br>&nbsp;<br>#ifdef __cplusplus<br>}<br>#endif<br>&nbsp;<br>#endif //__FILE_LOCK_HPP__
<br>&nbsp;<br><br>------------------------华丽分割线-----------------------------<br>//filelock.cpp<br>&nbsp;<br>#include &lt;fcntl.h&gt;
<br>#include &lt;unistd.h&gt;
<br>&nbsp;<br>#include "filelock.h";
<br>&nbsp;<br>int file_lock(int fd){
<br>&nbsp; struct flock s_flock;
<br>&nbsp; s_flock.l_type = F_WRLCK;
<br>&nbsp;<br>&nbsp; s_flock.l_whence = SEEK_SET;
<br>&nbsp; s_flock.l_start = 0;
<br>&nbsp; s_flock.l_len = 0;
<br>&nbsp; s_flock.l_pid = getpid();
<br>&nbsp;&nbsp;
<br>&nbsp; //F_SETLKW对加锁操作进行阻塞，
<br>&nbsp; //F_SETLK不对加锁操作进行阻塞，立即返回
<br>&nbsp; return fcntl(fd, F_SETLKW, &amp;s_flock);
<br>}
<br>&nbsp;<br>&nbsp;<br>int file_unlock(int fd){
<br>&nbsp; return fcntl(fd, F_SETLKW, F_UNLCK);
<br>}
<br>&nbsp;<br><br>---------------------------------华丽的分割线--------------------------<br>test.cpp<br>&nbsp;<br>#include "filelock.h"
<br><br>#include &lt;sys/types.h&gt;<br>#include &lt;sys/stat.h&gt;<br>#include &lt;fcntl.h&gt;<br><br>#include &lt;unistd.h&gt;<br>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;sys/wait.h&gt;<br>#include &lt;errno.h&gt;<br>&nbsp;<br>&nbsp;<br>int main(int argc,char *argv[]) {<br>&nbsp; int pid = -1;<br>&nbsp;<br>&nbsp; int i = 5;<br>&nbsp; while(i--){<br>&nbsp;&nbsp;&nbsp; if ((pid = fork()) &lt; 0) { //fork出错<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts("fork1 error");<br>&nbsp;&nbsp;&nbsp; } else if (pid &gt; 0) {//父进程<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sleep(5);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (waitpid(pid, NULL, 0) &lt; 0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts("waitpid error");<br><br>&nbsp;&nbsp;&nbsp; } else {//子进程<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sleep(1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int li_file = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int li_lck_st = -1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; li_file = open("tt.txt", O_WRONLY|O_CREAT, 0777);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( li_file &lt; 0 ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("file open error\n");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("li_file=[%d] pid=[%d]\n", li_file , getpid() );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; li_lck_st = file_lock(li_file);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sleep(5);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("li_lck_st=%d pid =%d\n", li_lck_st, getpid() );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file_unlock(li_file);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; close(li_file);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("close file pid=%d unlock\n", getpid());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br>&nbsp; return 0;
<br>}
<br>&nbsp;<br><br>------------------------------华丽分割线---------------------------<br>//makefile<br><br>#########################################################
<br>#Project: test
<br>#By: Khan.Lau
<br>#Description: test
<br>#########################################################
<br>&nbsp;<br>CC = gcc
<br>CXX = g++
<br>STRIP = strip
<br>AR = ar
<br><br>PROJ = $(shell pwd)<br>DLLPATH = $(shell find $(PROJ) -name *.so*)<br><br>LIBPATH = /usr<br>&nbsp;<br>INCS = -I$(LIBPATH)/include \<br>&nbsp;&nbsp;&nbsp; -I$(PROJ)/src/inc \<br>&nbsp;&nbsp;&nbsp; -I$(PROJ)/src<br><br><br>CXXINCS = -I$(LIBPATH)/include \<br>&nbsp;&nbsp;&nbsp; -I$(LIBPATH)/include/c++/4.3 \<br>&nbsp;&nbsp;&nbsp; -I$(LIBPATH)/include/c++/4.3/backward \<br>&nbsp;&nbsp;&nbsp; -I$(PROJ)/src/inc \<br>&nbsp;&nbsp;&nbsp; -I$(PROJ)/src<br><br>&nbsp;<br>CFLAGS = -g -Wall $(CXXINCS)&nbsp;
<br>#
<br>CONFIGURATION = release<br>#<br>BIN = test.exe<br>#LIB = lib/HuaWeiBsc.a<br>&nbsp;<br>#包路径<br>LIBS = -L$(PROJ)/lib&nbsp; \<br>&nbsp;&nbsp;&nbsp; -L$(LIBPATH)/lib -lz
<br>&nbsp;<br>SRCS = $(wildcard \<br>&nbsp;&nbsp;&nbsp; src/lib/*.cpp \<br>&nbsp;&nbsp;&nbsp; src/kernel/*.cpp)<br><br>&nbsp;<br>OBJBINS = $(SRCS:.cpp=.o)
<br>&nbsp;<br>&nbsp;<br>.c.o:
<br>&nbsp;&nbsp;&nbsp; $(CC) -o $@ -c $&lt; $(CFLAGS) <br>&nbsp;<br>.cpp.o:
<br>&nbsp;&nbsp;&nbsp; $(CXX) -o $@ -c $&lt; $(CFLAGS)&nbsp;
<br>&nbsp;<br>&nbsp;<br>COLORH=echo -en "\033[1;32;40m"
<br>COLORN=echo -en "\033[m"
<br>&nbsp;<br>&nbsp;<br>all : $(BIN)
<br><br>$(BIN) : $(OBJBINS)<br>&nbsp;&nbsp;&nbsp; $(CXX) -o $(CONFIGURATION)/$(BIN) $(OBJBINS) $(LIBS)
<br>&nbsp;&nbsp;&nbsp; @$(COLORN)
&nbsp;&nbsp;&nbsp; $(shell echo "$(BIN) build complete.")
<br>&nbsp;<br>#$(LIB) : $(OBJBINS)<br>#&nbsp;&nbsp;&nbsp; ar rc $(LIB) $(OBJBINS)<br><br>&nbsp;<br>clean :
<br>&nbsp;&nbsp;&nbsp; rm -f $(OBJBINS)
<br>&nbsp;&nbsp;&nbsp; rm -f $(BIN)
<br><br><br>-----------------------------华丽分割线--------------------------<br>测试环境 ubuntu 8.10,&nbsp; redhat 7.3, redhat fc3&nbsp; redhat enterprise 4.6<br>结果: <br>khan@khan-laptop:~/project/filelock/release$ ./test.exe <br>li_file=[3] pid=[10959]<br>li_lck_st=0 pid =10959<br>close file pid=10959 unlock<br>li_file=[3] pid=[10961]<br>li_lck_st=0 pid =10961<br>close file pid=10961 unlock<br>li_file=[3] pid=[10964]<br>li_lck_st=0 pid =10964<br>close file pid=10964 unlock<br>li_file=[3] pid=[10966]<br>li_lck_st=0 pid =10966<br>close file pid=10966 unlock<br>li_file=[3] pid=[10969]<br>li_lck_st=0 pid =10969<br>close file pid=10969 unlock<br><br>  <img src ="http://www.cppblog.com/Khan/aggbug/70218.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Khan/" target="_blank">Khan's Notebook</a> 2008-12-24 10:45 <a href="http://www.cppblog.com/Khan/archive/2008/12/24/70218.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux /proc/文件系统.</title><link>http://www.cppblog.com/Khan/archive/2008/10/24/64933.html</link><dc:creator>Khan's Notebook</dc:creator><author>Khan's Notebook</author><pubDate>Fri, 24 Oct 2008 06:16:00 GMT</pubDate><guid>http://www.cppblog.com/Khan/archive/2008/10/24/64933.html</guid><wfw:comment>http://www.cppblog.com/Khan/comments/64933.html</wfw:comment><comments>http://www.cppblog.com/Khan/archive/2008/10/24/64933.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/Khan/comments/commentRss/64933.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Khan/services/trackbacks/64933.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp; 最近要做一个jni给java来采集系统信息. 支持linux和windows<br>&nbsp;&nbsp;&nbsp; 采集的内容包括. 系统所有进程名, cpu占用率, 内存占用率, 系统内存大小, 已用内存大小, 可用内存大小, 分区大小, 已用分区磁盘空间, 可用分区磁盘空间. 系统信息. cpu核心总数..<br>&nbsp;&nbsp;&nbsp; 在windows下已经使用系统提供的api一一完成并经过调试. linux为了保证代码的统一. 也用了jni的方式<br><br>&nbsp;&nbsp;&nbsp; linux下我老以为会有类似的api提供. 翻了半天google, 最终决定还是从/proc文件系统开始来.<br>不过/proc方式的好处就是不论哪种语言. 只要他有操作文件的能力. 都可以获得这些信息. 而不局限于c或者c++<br><br>&nbsp;&nbsp;&nbsp; 要点1. /proc不是物理文件系统. 他是对内存数据的映射, 是驱动留给开发者和使用者的接口, 所以不管你什么时候用ls指令也好, 用stat来读 st_size也好. 他的大小都是0字节. <br>&nbsp;&nbsp;&nbsp; 要点2. 由于是vfs, 不要试图往/proc中扔文件或者目录<br><br>&nbsp;&nbsp;&nbsp; /proc目录中. 有不少信息. 我这次项目涉及到如下<br><br>&nbsp;&nbsp;&nbsp; /proc/stat&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //实时的系统信息, 我感兴趣的主要是cpu负载数据<br>&nbsp;&nbsp;&nbsp; /proc/loadavg&nbsp;&nbsp; //一段时间内 cpu负载的平均数 以及最近一次的pid<br>&nbsp;&nbsp;&nbsp; /proc/cpuinfo&nbsp;&nbsp; //cpu信息 频率 核心 支持特性<br>&nbsp;&nbsp;&nbsp; /proc/version&nbsp;&nbsp; //系统内核版本&nbsp; 系统发行版本 gcc版本<br><br>&nbsp;&nbsp;&nbsp; /proc目录下每个以数字命名的子目录都代表一个进程, 目录名则是他的pid<br>&nbsp;&nbsp;&nbsp; /proc/(pid)/cmdline&nbsp; 该进程启动时的命令,&nbsp; 系统核心进程应该是空的<br>&nbsp;&nbsp;&nbsp; /proc/(pid)/stat&nbsp;&nbsp;&nbsp;&nbsp; 里面记录着pid, 进程名(short_cmd)等等<br>&nbsp;&nbsp;&nbsp; /proc/(pid)/environ&nbsp; 记录着系统执行的环境变量<br><br>其他的改天碰到再看吧.<br><br> <img src ="http://www.cppblog.com/Khan/aggbug/64933.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Khan/" target="_blank">Khan's Notebook</a> 2008-10-24 14:16 <a href="http://www.cppblog.com/Khan/archive/2008/10/24/64933.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>c语言（a ＜ b ＜ c ）的陷阱</title><link>http://www.cppblog.com/Khan/archive/2008/10/23/64835.html</link><dc:creator>Khan's Notebook</dc:creator><author>Khan's Notebook</author><pubDate>Thu, 23 Oct 2008 08:35:00 GMT</pubDate><guid>http://www.cppblog.com/Khan/archive/2008/10/23/64835.html</guid><wfw:comment>http://www.cppblog.com/Khan/comments/64835.html</wfw:comment><comments>http://www.cppblog.com/Khan/archive/2008/10/23/64835.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/Khan/comments/commentRss/64835.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Khan/services/trackbacks/64835.html</trackback:ping><description><![CDATA[很久没有碰c/c++了, 近两年都是java为主, 偶尔用一下c/c++<br><br>(a&lt;b&lt;c) 这种写法我以前从来没有用过. 今天突然有网友提起来, 我习惯性的在脑海中把其翻译成<br>(a&lt;b &amp;&amp; b&lt;c) 酿成了一些小错误. 我悔过了.<br><br>网友给我扔来了c99的标准<br>&#167;6.5.9 第86页 89) The expression a&lt;b&lt;c is not interpreted as in ordinary mathematics. As the syntax indicates, it<br>means (a&lt;b)&lt;c; in other words, &#8216;&#8216;if a is less than b, compare 1 to c; otherwise, compare 0 to c&#8217;&#8217;.<br><br>意思也就是说. (a&lt;b&lt;c) 按照从左到右的方式开始运算<br>1.( (a&lt;b) &lt; c )<br>2.a&lt;b ?&nbsp; TRUE : FALSE; <br>3.所以, 最终表达式运算的是 (1&lt;c) 或者 (0&lt;c)<br><br>C语言中. 虽然任何不等于0的数为真. 但是实际在宏定义中 TRUE == 1&nbsp; FALSE == 0;<img src ="http://www.cppblog.com/Khan/aggbug/64835.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Khan/" target="_blank">Khan's Notebook</a> 2008-10-23 16:35 <a href="http://www.cppblog.com/Khan/archive/2008/10/23/64835.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sourceforge又被封了...你们想让我说什么呢....</title><link>http://www.cppblog.com/Khan/archive/2008/07/07/55576.html</link><dc:creator>Khan's Notebook</dc:creator><author>Khan's Notebook</author><pubDate>Mon, 07 Jul 2008 15:28:00 GMT</pubDate><guid>http://www.cppblog.com/Khan/archive/2008/07/07/55576.html</guid><wfw:comment>http://www.cppblog.com/Khan/comments/55576.html</wfw:comment><comments>http://www.cppblog.com/Khan/archive/2008/07/07/55576.html#Feedback</comments><slash:comments>18</slash:comments><wfw:commentRss>http://www.cppblog.com/Khan/comments/commentRss/55576.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Khan/services/trackbacks/55576.html</trackback:ping><description><![CDATA[&nbsp;&nbsp; 此贴是原创, 又不算技术, 关乎开源, 但是又无关软件...矛盾啊....<br>&nbsp;&nbsp; 半夜想down个mingw32... 去sourceforge.发现又上不去了. 凭直觉, 网站出问题的机会几乎没有. 开了个jondo, 果然能上去.<br>&nbsp;&nbsp; 上面的人又封sourceforge了.从06年LUPA事件到现在, 又开始了.<br>&nbsp;&nbsp;&nbsp; 开jondo down东西. 速度不足2k. tor速度更慢, 大家有没有什么好的工具.&nbsp; 这个时势没办法. 不能忍受就要学会享受.<br>&nbsp;&nbsp;&nbsp; 世道真是越来越乱了......<br><br><img src ="http://www.cppblog.com/Khan/aggbug/55576.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Khan/" target="_blank">Khan's Notebook</a> 2008-07-07 23:28 <a href="http://www.cppblog.com/Khan/archive/2008/07/07/55576.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VC6 与GCC-avr交叉环境配置</title><link>http://www.cppblog.com/Khan/archive/2008/06/24/54457.html</link><dc:creator>Khan's Notebook</dc:creator><author>Khan's Notebook</author><pubDate>Tue, 24 Jun 2008 04:05:00 GMT</pubDate><guid>http://www.cppblog.com/Khan/archive/2008/06/24/54457.html</guid><wfw:comment>http://www.cppblog.com/Khan/comments/54457.html</wfw:comment><comments>http://www.cppblog.com/Khan/archive/2008/06/24/54457.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/Khan/comments/commentRss/54457.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Khan/services/trackbacks/54457.html</trackback:ping><description><![CDATA[01、在C:或其他盘下安装VC6.0<br>02、在C:或其他盘下新建ECC文件夹<br>03、在C:\ECC目录下安装WinAVR-20040720版<br>04、在C:\ECC目录下新建common文件夹<br>05、把lib和inc文件夹copy到C:\ECC\common目录下<br>06、把cl.exe; lhex.exe; link.exe; lview.exe; nmake.exe; rc.exe; sp.exe; ecc.reg; 这8个文件COPY到C:\ECC目录下<br>07、把EccAddin.pdb和EccAddin.dll 文件copy到VC目录下的\common\msdev98\addins 目录下<br>08、把GccWizard.awx 文件copy到 VC目录下的\common\msdev98\template 目录下<br>09、在任何目录下安装port95nt.exe<br>10、把avr5.x 文件copy到C:\ECC\Winavr\avr\lib\ldscripts 目录下<br>11、把usertype&nbsp; 文件copy到 VC目录下的\common\msdev98\bin 目录下<br>12、用记事本打开ecc.reg修改路径并保存，双击此文件添加到注册表中<br>13、打开VC++6.0; 在tools菜单-&gt;options-&gt;directories中将 C:\ECC\common\inc和C:\ECC\winavr\include 两个目录添加到include file选项中。同时将C:\ECC目录添加到executable files 选项中；并将之移到顶部。<br><br>SP.exe 烧录的配置自己google吧<br><br>备注:<br>07 把EccAddin.pdb和EccAddin.dll 文件copy到VC目录下的\common\msdev98\addins 目录下<br>这俩文件是自己写d<br><br> <img src ="http://www.cppblog.com/Khan/aggbug/54457.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Khan/" target="_blank">Khan's Notebook</a> 2008-06-24 12:05 <a href="http://www.cppblog.com/Khan/archive/2008/06/24/54457.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>GCC Mingw编译JNI dll要点</title><link>http://www.cppblog.com/Khan/archive/2008/06/23/54364.html</link><dc:creator>Khan's Notebook</dc:creator><author>Khan's Notebook</author><pubDate>Mon, 23 Jun 2008 04:57:00 GMT</pubDate><guid>http://www.cppblog.com/Khan/archive/2008/06/23/54364.html</guid><wfw:comment>http://www.cppblog.com/Khan/comments/54364.html</wfw:comment><comments>http://www.cppblog.com/Khan/archive/2008/06/23/54364.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Khan/comments/commentRss/54364.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Khan/services/trackbacks/54364.html</trackback:ping><description><![CDATA[本来想做一个win32平台下, 由于vc没有psapi.dll的库. 所以选择了mingw包和gcc编译器.<br><br>java部分<br>这里主要是申明接口. javah工具会根据你声明的接口自动生成对于的.h头文件<br><br>//SystemInfo.java<br>package com.khan.system;<br><br>public abstract class SystemInfo<br>{<br>&nbsp;&nbsp;&nbsp; // public: ................................................................<br>&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * A simple class to represent data snapshots taken by {@link #makeCPUUsageSnapshot}.<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; public static final class CPUUsageSnapshot {<br>&nbsp;&nbsp;&nbsp; public final long m_time, m_CPUTime;<br>&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // constructor is private to ensure that makeCPUUsageSnapshot()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // is used as the factory method for this class:<br>&nbsp;&nbsp;&nbsp; private CPUUsageSnapshot (final long time, final long CPUTime) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_time = time;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_CPUTime = CPUTime;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; &nbsp;<br>&nbsp; } // end of nested class<br><br><br><br>&nbsp;&nbsp;&nbsp; // Custom exception class for throwing<br>&nbsp; public static final class NegativeCPUTime extends Exception {}<br><br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Minimum time difference [in milliseconds] enforced for the inputs into<br>&nbsp;&nbsp;&nbsp; * {@link #getProcessCPUUsage(SystemInfo.CPUUsageSnapshot,SystemInfo.CPUUsageSnapshot)}.<br>&nbsp;&nbsp;&nbsp; * The motivation for this restriction is the fact that &lt;CODE&gt;System.currentTimeMillis()&lt;/CODE&gt;<br>&nbsp;&nbsp;&nbsp; * on some systems has a low resolution (e.g., 10ms on win32). The current value<br>&nbsp;&nbsp;&nbsp; * is 100 ms.<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; public static final int MIN_ELAPSED_TIME = 100;<br><br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Creates a CPU usage data snapshot by associating CPU time used with system<br>&nbsp;&nbsp;&nbsp; * time. The resulting data can be fed into<br>&nbsp;&nbsp;&nbsp; * {@link #getProcessCPUUsage(SystemInfo.CPUUsageSnapshot,SystemInfo.CPUUsageSnapshot)}.<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; public static CPUUsageSnapshot makeCPUUsageSnapshot() throws SystemInfo.NegativeCPUTime {<br>&nbsp;&nbsp;&nbsp; long prCPUTime = getProcessCPUTime ();<br>&nbsp;&nbsp;&nbsp; if (prCPUTime&lt;0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new NegativeCPUTime();<br>&nbsp;&nbsp;&nbsp; return new CPUUsageSnapshot (System.currentTimeMillis (), getProcessCPUTime ());<br>&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Computes CPU usage (fraction of 1.0) between &lt;CODE&gt;start.m_CPUTime&lt;/CODE&gt; and<br>&nbsp;&nbsp;&nbsp; * &lt;CODE&gt;end.m_CPUTime&lt;/CODE&gt; time points [1.0 corresponds to 100% utilization of<br>&nbsp;&nbsp;&nbsp; * all processors].<br>&nbsp;&nbsp;&nbsp; *<br>&nbsp;&nbsp;&nbsp; * @throws IllegalArgumentException if start and end time points are less than<br>&nbsp;&nbsp;&nbsp; * {@link #MIN_ELAPSED_TIME} ms apart.<br>&nbsp;&nbsp;&nbsp; * @throws IllegalArgumentException if either argument is null;<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; public static double getProcessCPUUsage (final CPUUsageSnapshot start, final CPUUsageSnapshot end) {<br>&nbsp;&nbsp;&nbsp; if (start == null)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new IllegalArgumentException ("null input: start");<br>&nbsp;&nbsp;&nbsp; if (end == null)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new IllegalArgumentException ("null input: end");<br>&nbsp;&nbsp;&nbsp; if (end.m_time &lt; start.m_time + MIN_ELAPSED_TIME)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new IllegalArgumentException ("end time must be at least " + MIN_ELAPSED_TIME + " ms later than start time");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp; return ((double)(end.m_CPUTime - start.m_CPUTime)) / (end.m_time - start.m_time);<br>&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Returns the PID of the current process. The result is useful when you need<br>&nbsp;&nbsp;&nbsp; * to integrate a Java app with external tools.<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; public static native int getProcessID ();<br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Returns the number of processors on machine<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; public static native int getCPUs ();<br><br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Returns CPU (kernel + user) time used by the current process [in milliseconds].<br>&nbsp;&nbsp;&nbsp; * The returned value is adjusted for the number of processors in the system.<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; public static native long getProcessCPUTime ();<br><br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Returns CPU (kernel + user) time used by the current process [in perecents].<br>&nbsp;&nbsp;&nbsp; * The returned value is either CPU percentage, or zero if this is not supported by OS.<br>&nbsp;&nbsp;&nbsp; * Currently it is supported by Solaris8, and not supported by Windows XP<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; public static native double getProcessCPUPercentage();<br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Returns maximum memory available in the system.<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; public static native long getMaxMem ();<br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Returns current free memory in the system.<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; public static native long getFreeMem ();<br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Returns system name info like "uname" command output<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; public static native String getSysInfo ();<br><br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Returns CPU usage (fraction of 1.0) so far by the current process. This is a total<br>&nbsp;&nbsp;&nbsp; * for all processors since the process creation time.<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; public static native double getProcessCPUUsage ();<br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Returns current space allocated for the process, in Kbytes. Those pages may or may not be in memory.<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; public static native long getMemoryUsage();<br><br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Returns current process space being resident in memory, in Kbytes.<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; public static native long getMemoryResident();<br><br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Sets the system native process PID for which all measurements will be done.<br>&nbsp;&nbsp;&nbsp; * If this method is not called then the current JVM pid will act as a default.<br>&nbsp;&nbsp;&nbsp; * Returns the native-dependent error code, or 0 in case of success.<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; public static native int setPid(int pid);<br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Closes native-dependent process handle, if necessary.<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; public static native int detachProcess();<br><br>&nbsp;&nbsp;&nbsp; // protected: .............................................................<br><br>&nbsp;&nbsp;&nbsp; // package: ...............................................................<br><br>&nbsp;&nbsp;&nbsp; // private: ...............................................................<br><br><br>&nbsp; private SystemInfo() {} // prevent subclassing<br><br>&nbsp; private static final String SILIB = "SystemInfo";<br><br>&nbsp; static {<br>&nbsp;&nbsp;&nbsp; // loading a native lib in a static initializer ensures that it is<br>&nbsp;&nbsp;&nbsp; // available done before any method in this class is called:<br>&nbsp;&nbsp;&nbsp; try {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.loadLibrary (SILIB);<br>&nbsp;&nbsp;&nbsp; }catch (UnsatisfiedLinkError e){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("native lib '" + SILIB<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + "' not found in 'java.library.path': "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + System.getProperty ("java.library.path"));<br>&nbsp;&nbsp;&nbsp; }catch (Exception e){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(e.getMessage());<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br><br>} // end of class<br><br><br>//AppMain.java 测试文件<br>package com.khan.system;<br><br>public class AppMain {<br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp;&nbsp; * Default constructor<br>&nbsp;&nbsp;&nbsp;&nbsp; */<br>&nbsp;&nbsp;&nbsp; public AppMain() {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // TODO: Add constructor code here<br>&nbsp;&nbsp;&nbsp; }<br><br><br>&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.sleep(1000);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("getMaxMem:" + SystemInfo.getMaxMem());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("getCPUs:" + SystemInfo.getCPUs());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("getSysInfo:" + SystemInfo.getSysInfo());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }catch (Exception e){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(e.getMessage());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br><br>}<br><br>java部分工程文件. 等同与makefile<br>ant build.xml<br><br>&lt;project name="IpNet" default="build" basedir="."&gt;<br>&nbsp; &lt;description&gt;<br>&nbsp;&nbsp;&nbsp; simple example build file<br>&nbsp; &lt;/description&gt;<br>&nbsp; &lt;!-- set global properties for this build --&gt;<br>&nbsp; &lt;property name="name" value="IpNet"/&gt;<br>&nbsp; &lt;property name="src" location="src"/&gt;<br>&nbsp; &lt;property name="build" location="build"/&gt;<br>&nbsp; &lt;property name="dist"&nbsp; location="dist"/&gt;<br>&nbsp; &lt;property name="web"&nbsp; location="web/WEB-INF/lib"/&gt;<br><br>&nbsp; &lt;path id="master-classpath"&gt;<br>&nbsp;&nbsp;&nbsp; &lt;fileset dir="./lib"&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;include name="*.jar"/&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/fileset&gt;<br>&nbsp; &lt;/path&gt;<br><br>&nbsp; &lt;target name="init"&gt;<br>&nbsp;&nbsp;&nbsp; &lt;tstamp/&gt;<br>&nbsp;&nbsp;&nbsp; &lt;mkdir dir="${build}"/&gt;<br>&nbsp;&nbsp;&nbsp; &lt;mkdir dir="${dist}"/&gt;<br>&nbsp; &lt;/target&gt;<br><br>&nbsp; &lt;target name="build" depends="init" description="compile the source " &gt;<br>&nbsp;&nbsp;&nbsp; &lt;javac srcdir="${src}" destdir="${build}"&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;compilerarg value="-Xlint:unchecked"/&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;compilerarg value="-deprecation"/&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;classpath refid="master-classpath"/&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/javac&gt;<br>&nbsp; <br>&nbsp;&nbsp;&nbsp; &lt;copy todir="${build}" preservelastmodified="true"&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;fileset dir="${src}"&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;include name="*.class"/&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/fileset&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/copy&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp; &lt;jar jarfile="${dist}/${name}.jar" compress="true"&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;fileset dir="${build}"&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;include name="**"/&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/fileset&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/jar&gt;<br><br>&nbsp;&nbsp;&nbsp; &lt;copy todir="${web}" &gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;fileset dir="${dist}"&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;include name="${name}.jar"/&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/fileset&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/copy&gt;<br>&nbsp; &lt;/target&gt;<br>&nbsp;<br>&nbsp; &lt;target name="clean" description="clean up" &gt;<br>&nbsp;&nbsp;&nbsp; &lt;delete dir="${build}"/&gt;<br>&nbsp;&nbsp;&nbsp; &lt;delete dir="${dist}"/&gt;<br>&nbsp;&nbsp;&nbsp; &lt;delete file="${web}/${name}.jar"/&gt;<br>&nbsp; &lt;/target&gt;<br>&lt;/project&gt;<br><br>在工程目录下ant 编译工程<br>build目录为本工程目标二进制文件目录. 编译后的class在此目录下<br>然后到build目录下<br>javah javah -jni com.khan.system.SystemInfo //注意, 一定要使用包全路径. 如果不是default包的话.<br>会在此目录下生成3个.h文件<br>com_khan_system_SystemInfo.h<br>com_khan_system_SystemInfo_CPUUsageSnapshot.h<br>com_khan_system_SystemInfo_NegativeCPUTime.h<br><br><br>java这边的准备工作完成<br><br>接下来处理c部分<br>新建一个c工程. 我用gcc的. 所以这些部分我手工完成的<br>将刚刚的.h文件实现<br><br>/* ------------------------------------------------------------------------- */<br>/*<br>&nbsp;* An implementation of JNI methods in com.vladium.utils.SystemInformation<br>&nbsp;* class. The author compiled it using Microsoft Visual C++ and GCC for Win32 but the code<br>&nbsp;* should be easy to use with any compiler for win32 platform.<br>&nbsp;*<br>&nbsp;* For simplicity, this implementaion assumes JNI 1.2+ and omits error handling.<br>&nbsp;*<br>&nbsp;* Enhanced by Peter V. Mikhalenko (C) 2004, Deutsche Bank [peter@mikhalenko.com]<br>&nbsp;* Original source (C) 2002, Vladimir Roubtsov [vlad@trilogy.com]<br>&nbsp;*/<br>/* ------------------------------------------------------------------------- */<br><br><br>#include &lt;windows.h&gt;<br>#include &lt;stdio.h&gt;<br>#include &lt;process.h&gt;<br>#include &lt;winbase.h&gt;<br>#include &lt;psapi.h&gt;<br>#include &lt;string.h&gt;<br><br><br>#include "include/com_khan_system_SystemInfo.h"<br><br><br><br>static jint s_PID;<br>static HANDLE s_currentProcess;<br>static int alreadyDetached;<br>static int s_numberOfProcessors;<br>static SYSTEM_INFO systemInfo;<br>static WORD processorArchitecture;<br>static DWORD pageSize;<br>static DWORD processorType;<br>static WORD processorLevel;<br>static WORD processorRevision;<br><br>#define INFO_BUFFER_SIZE 32768<br>#define BUFSIZE 2048<br><br>//BOOL flll = TRUE;<br>/* ------------------------------------------------------------------------- */<br><br>/*<br>&nbsp;* A helper function for converting FILETIME to a LONGLONG [safe from memory<br>&nbsp;* alignment point of view].<br>&nbsp;*/<br>static LONGLONG fileTimeToInt64 (const FILETIME * time)<br>{<br>&nbsp;&nbsp;&nbsp; ULARGE_INTEGER _time;<br><br>&nbsp;&nbsp;&nbsp; _time.LowPart = time-&gt;dwLowDateTime;<br>&nbsp;&nbsp;&nbsp; _time.HighPart = time-&gt;dwHighDateTime;<br><br>&nbsp;&nbsp;&nbsp; return _time.QuadPart;<br>}<br>/* ......................................................................... */<br><br>/*<br>&nbsp;* This method was added in JNI 1.2. It is executed once before any other<br>&nbsp;* methods are called and is ostensibly for negotiating JNI spec versions, but<br>&nbsp;* can also be conveniently used for initializing variables that will not<br>&nbsp;* change throughout the lifetime of this process.<br>&nbsp;*/<br>JNIEXPORT jint JNICALL JNI_OnLoad (JavaVM * vm, void * reserved)<br>{<br>&nbsp; s_PID = _getpid ();<br>&nbsp; s_currentProcess = GetCurrentProcess ();<br>&nbsp; //externalCPUmon = 0;<br>&nbsp; alreadyDetached = 0;<br><br>&nbsp; GetSystemInfo (&amp;systemInfo);<br>&nbsp; s_numberOfProcessors = systemInfo.dwNumberOfProcessors;<br>&nbsp; processorArchitecture = systemInfo.wProcessorArchitecture;<br>&nbsp; pageSize = systemInfo.dwPageSize;<br>&nbsp; processorType = systemInfo.dwProcessorType;<br>&nbsp; processorLevel = systemInfo.wProcessorLevel;<br>&nbsp; processorRevision = systemInfo.wProcessorRevision;<br>&nbsp; printf("SystemInfo.dll is Loaded");<br>&nbsp; return JNI_VERSION_1_2;<br>}<br>/* ......................................................................... */<br><br>JNIEXPORT void JNICALL<br>JNI_OnUnload (JavaVM * vm, void * reserved)<br>{<br>&nbsp; if (!alreadyDetached &amp;&amp; s_currentProcess!=NULL) {<br>&nbsp;&nbsp;&nbsp; CloseHandle(s_currentProcess);<br>&nbsp;&nbsp;&nbsp; printf("[JNI Unload] Detached from native process.");<br>&nbsp;&nbsp;&nbsp; fflush(stdout);<br>&nbsp; }<br>&nbsp; printf("SystemInfo.dll is UnLoaded");<br>}<br>/* ......................................................................... */<br><br>/*<br>&nbsp;* Class:&nbsp;&nbsp;&nbsp;&nbsp; com_vladium_utils_SystemInformation<br>&nbsp;* Method:&nbsp;&nbsp;&nbsp; getCPUs<br>&nbsp;* Signature: ()I<br>&nbsp;*/<br>JNIEXPORT jint JNICALL Java_com_khan_system_SystemInfo_getCPUs(JNIEnv * env, jclass cls)<br>{<br>&nbsp;&nbsp;&nbsp; return (jint)s_numberOfProcessors;<br>}<br>/* ......................................................................... */<br><br><br><br>/*<br>&nbsp;* Class:&nbsp;&nbsp;&nbsp;&nbsp; com_vladium_utils_SystemInformation<br>&nbsp;* Method:&nbsp;&nbsp;&nbsp; getProcessID<br>&nbsp;* Signature: ()I<br>&nbsp;*/<br>JNIEXPORT jint JNICALL<br>Java_com_khan_system_SystemInfo_getProcessID(JNIEnv * env, jclass cls)<br>{<br>&nbsp;&nbsp;&nbsp; return s_PID;<br>}<br>/* ......................................................................... */<br><br>/*<br>&nbsp;* Class:&nbsp;&nbsp;&nbsp;&nbsp; com_vladium_utils_SystemInformation<br>&nbsp;* Method:&nbsp;&nbsp;&nbsp; setPid<br>&nbsp;* Signature: ()I<br>&nbsp;*/<br>JNIEXPORT jint JNICALL<br>Java_com_khan_system_SystemInfo_setPid(JNIEnv * env, jclass cls, jint pid)<br>{<br>&nbsp;&nbsp;&nbsp; DWORD errCode;<br>&nbsp;&nbsp;&nbsp; LPVOID lpMsgBuf;<br>&nbsp;&nbsp;&nbsp; s_PID = pid;<br>&nbsp;&nbsp;&nbsp; s_currentProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,pid);<br>&nbsp;&nbsp;&nbsp; if (s_currentProcess==NULL) {<br>&nbsp;&nbsp;&nbsp;&nbsp; errCode = GetLastError();<br>&nbsp;&nbsp;&nbsp;&nbsp; FormatMessage(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FORMAT_MESSAGE_ALLOCATE_BUFFER |<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FORMAT_MESSAGE_FROM_SYSTEM,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; errCode,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (LPTSTR) &amp;lpMsgBuf,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0, NULL );<br>&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp; printf("[CPUmon] Could not attach to native process. Error code: %ld Error description: %s", errCode, (char *)lpMsgBuf);<br>&nbsp;&nbsp;&nbsp;&nbsp; fflush(stdout);<br>&nbsp;&nbsp;&nbsp;&nbsp; LocalFree(lpMsgBuf);<br>&nbsp;&nbsp;&nbsp;&nbsp; return errCode;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; printf("[CPUmon] Attached to native process.");<br>&nbsp;&nbsp;&nbsp; fflush(stdout);<br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br>/* ......................................................................... */<br><br>/*<br>&nbsp;* Class:&nbsp;&nbsp;&nbsp;&nbsp; com_vladium_utils_SystemInformation<br>&nbsp;* Method:&nbsp;&nbsp;&nbsp; detachProcess<br>&nbsp;* Signature: ()I<br>&nbsp;*/<br>JNIEXPORT jint JNICALL<br>Java_com_khan_system_SystemInfo_detachProcess(JNIEnv * env, jclass cls)<br>{<br>&nbsp;&nbsp;&nbsp; if (!alreadyDetached &amp;&amp; s_currentProcess!=NULL) {<br>&nbsp;&nbsp;&nbsp;&nbsp; CloseHandle(s_currentProcess);<br>&nbsp;&nbsp;&nbsp;&nbsp; alreadyDetached = 1;<br>&nbsp;&nbsp;&nbsp;&nbsp; printf("[CPUmon] Detached from native process.");<br>&nbsp;&nbsp;&nbsp;&nbsp; fflush(stdout);<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br>/* ......................................................................... */<br><br>/*<br>&nbsp;* Class:&nbsp;&nbsp;&nbsp;&nbsp; com_vladium_utils_SystemInformation<br>&nbsp;* Method:&nbsp;&nbsp;&nbsp; getProcessCPUTime<br>&nbsp;* Signature: ()J<br>&nbsp;*/<br>JNIEXPORT jlong JNICALL<br>Java_com_khan_system_SystemInfo_getProcessCPUTime (JNIEnv * env, jclass cls)<br>{<br>&nbsp;&nbsp;&nbsp; FILETIME creationTime, exitTime, kernelTime, userTime;<br>&nbsp;&nbsp;&nbsp; DWORD errCode;<br>&nbsp;&nbsp;&nbsp; LPVOID lpMsgBuf;<br>&nbsp; <br>&nbsp;&nbsp;&nbsp; BOOL resultSuccessful = GetProcessTimes (s_currentProcess, &amp; creationTime, &amp; exitTime, &amp; kernelTime, &amp; userTime);<br>&nbsp;&nbsp;&nbsp; if (!resultSuccessful) {<br>&nbsp;&nbsp;&nbsp;&nbsp; errCode = GetLastError();<br>&nbsp;&nbsp;&nbsp;&nbsp; FormatMessage(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FORMAT_MESSAGE_ALLOCATE_BUFFER |<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FORMAT_MESSAGE_FROM_SYSTEM,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; errCode,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (LPTSTR) &amp;lpMsgBuf,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0, NULL );<br>&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp; printf("[CPUmon] An error occured while trying to get CPU time. Error code: %ld Error description: %s", errCode, (char *)lpMsgBuf);<br><br>&nbsp;&nbsp;&nbsp;&nbsp; fflush(stdout);<br>&nbsp;&nbsp;&nbsp;&nbsp; LocalFree(lpMsgBuf);<br>&nbsp;&nbsp;&nbsp;&nbsp; return -1;<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; return (jlong) ((fileTimeToInt64 (&amp; kernelTime) + fileTimeToInt64 (&amp; userTime)) /<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (s_numberOfProcessors * 10000));<br>}<br>/* ......................................................................... */<br><br>/*<br>&nbsp;* Class:&nbsp;&nbsp;&nbsp;&nbsp; com_vladium_utils_SystemInformation<br>&nbsp;* Method:&nbsp;&nbsp;&nbsp; getMaxMem<br>&nbsp;* Signature: ()J<br>&nbsp;*/<br>JNIEXPORT jlong JNICALL<br>Java_com_khan_system_SystemInfo_getMaxMem(JNIEnv * env, jclass cls)<br>{<br>&nbsp;MEMORYSTATUS stat;<br>&nbsp;GlobalMemoryStatus (&amp;stat);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (jlong)(stat.dwTotalPhys/1024);<br>}<br>/* ......................................................................... */<br><br>/*<br>&nbsp;* Class:&nbsp;&nbsp;&nbsp;&nbsp; com_vladium_utils_SystemInformation<br>&nbsp;* Method:&nbsp;&nbsp;&nbsp; getFreeMem<br>&nbsp;* Signature: ()J<br>&nbsp;*/<br>JNIEXPORT jlong JNICALL<br>Java_com_khan_system_SystemInfo_getFreeMem (JNIEnv * env, jclass cls)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MEMORYSTATUS stat;<br>&nbsp;GlobalMemoryStatus (&amp;stat);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (jlong)(stat.dwAvailPhys/1024);<br>}<br>/* ......................................................................... */<br><br><br>/* define min elapsed time (in units of 10E-7 sec): */<br>#define MIN_ELAPSED_TIME (10000)<br><br>/*<br>&nbsp;* Class:&nbsp;&nbsp;&nbsp;&nbsp; com_vladium_utils_SystemInformation<br>&nbsp;* Method:&nbsp;&nbsp;&nbsp; getProcessCPUUsage<br>&nbsp;* Signature: ()D<br>&nbsp;*/<br>JNIEXPORT jdouble JNICALL<br>Java_com_khan_system_SystemInfo_getProcessCPUUsage(JNIEnv * env, jclass cls)<br>{<br>&nbsp;&nbsp;&nbsp; FILETIME creationTime, exitTime, kernelTime, userTime, nowTime; <br>&nbsp;&nbsp;&nbsp; LONGLONG elapsedTime;<br>&nbsp;&nbsp;&nbsp; DWORD errCode;<br>&nbsp;&nbsp;&nbsp; LPVOID lpMsgBuf;<br>&nbsp; <br>&nbsp;&nbsp;&nbsp; BOOL resultSuccessful = GetProcessTimes (s_currentProcess, &amp; creationTime, &amp; exitTime, &amp; kernelTime, &amp; userTime);<br>&nbsp;&nbsp;&nbsp; if (!resultSuccessful) {<br>&nbsp;&nbsp;&nbsp;&nbsp; errCode = GetLastError();<br>&nbsp;&nbsp;&nbsp;&nbsp; FormatMessage(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; errCode,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (LPTSTR) &amp;lpMsgBuf,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0, NULL );<br>&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp; printf("[CPUmon] An error occured while trying to get CPU time. Error code: %ld Error description: %s", errCode, (char *)lpMsgBuf);<br>&nbsp;&nbsp;&nbsp;&nbsp; fflush(stdout);<br>&nbsp;&nbsp;&nbsp;&nbsp; LocalFree(lpMsgBuf);<br>&nbsp;&nbsp;&nbsp;&nbsp; return -1.0;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; GetSystemTimeAsFileTime (&amp; nowTime);<br><br>&nbsp;&nbsp;&nbsp; /*<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NOTE: win32 system time is not very precise [~10ms resolution], use<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sufficiently long sampling intervals if you make use of this method.<br>&nbsp;&nbsp;&nbsp; */<br>&nbsp; <br>&nbsp;&nbsp;&nbsp; elapsedTime = fileTimeToInt64 (&amp; nowTime) - fileTimeToInt64 (&amp; creationTime);<br>&nbsp; <br>&nbsp;&nbsp;&nbsp; if (elapsedTime &lt; MIN_ELAPSED_TIME)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0.0;<br>&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ((jdouble) (fileTimeToInt64 (&amp; kernelTime) + fileTimeToInt64 (&amp; userTime))) /<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (s_numberOfProcessors * elapsedTime);<br>}<br>/* ......................................................................... */<br><br>/*<br>&nbsp;* Class:&nbsp;&nbsp;&nbsp;&nbsp; com_vladium_utils_SystemInformation<br>&nbsp;* Method:&nbsp;&nbsp;&nbsp; getProcessCPUPercentage<br>&nbsp;* Signature: ()D<br>&nbsp;*/<br>JNIEXPORT jdouble JNICALL<br>Java_com_khan_system_SystemInfo_getProcessCPUPercentage (JNIEnv * env, jclass cls)<br>{<br>&nbsp;// Not implemented on Windows<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (jdouble)(-1.0);<br>}<br>/* ......................................................................... */<br><br>/*<br>&nbsp;* Class:&nbsp;&nbsp;&nbsp;&nbsp; com_vladium_utils_SystemInformation<br>&nbsp;* Method:&nbsp;&nbsp;&nbsp; getMemoryUsage<br>&nbsp;* Signature: ()J<br>&nbsp;*/<br>JNIEXPORT jlong JNICALL<br>Java_com_khan_system_SystemInfo_getMemoryUsage (JNIEnv * env, jclass cls)<br>{<br>&nbsp;&nbsp;&nbsp; PROCESS_MEMORY_COUNTERS pmc;<br>&nbsp; <br>&nbsp;&nbsp;&nbsp; if ( GetProcessMemoryInfo( s_currentProcess, &amp;pmc, sizeof(pmc)) )<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;return (jlong)(pmc.PagefileUsage/1024);<br>&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;return (jlong)(0);<br>&nbsp;&nbsp;&nbsp; }<br>}<br>/* ......................................................................... */<br><br>/*<br>&nbsp;* Class:&nbsp;&nbsp;&nbsp;&nbsp; com_vladium_utils_SystemInformation<br>&nbsp;* Method: getMemoryResident * Signature: ()J<br>*/<br>JNIEXPORT jlong JNICALL<br>Java_com_khan_system_SystemInfo_getMemoryResident(JNIEnv * env, jclass cls)<br>{<br>&nbsp;&nbsp;&nbsp; PROCESS_MEMORY_COUNTERS pmc;<br>&nbsp; <br>&nbsp;&nbsp;&nbsp; if ( GetProcessMemoryInfo( s_currentProcess, &amp;pmc, sizeof(pmc)) )<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (jlong)(pmc.WorkingSetSize/1024);<br>&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (jlong)(0);<br>&nbsp;&nbsp;&nbsp; }<br>}<br><br><br>/*<br>&nbsp;* Class:&nbsp;&nbsp;&nbsp;&nbsp; com_vladium_utils_SystemInformation<br>&nbsp;* Method:&nbsp;&nbsp;&nbsp; getSysInfo<br>&nbsp;* Signature: ()S<br>&nbsp;*/<br>JNIEXPORT jstring JNICALL<br>Java_com_khan_system_SystemInfo_getSysInfo(JNIEnv * env, jclass cls)<br>{<br>&nbsp; char buf[2048];<br>&nbsp; char buf2[512];<br>&nbsp; jstring retval;<br>&nbsp; OSVERSIONINFOEX osvi;<br>&nbsp; BOOL bOsVersionInfoEx;<br>&nbsp; TCHAR infoBuf[INFO_BUFFER_SIZE];<br><br>&nbsp; DWORD bufCharCount = INFO_BUFFER_SIZE;<br>&nbsp; *buf = 0; //c语言. 变量定义所有代码在前<br>&nbsp; *buf2 = 0;<br>&nbsp; ZeroMemory(&amp;osvi, sizeof(OSVERSIONINFOEX));<br>&nbsp; osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);<br>&nbsp; if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &amp;osvi)) )<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);<br>&nbsp;&nbsp;&nbsp; if (! GetVersionEx ( (OSVERSIONINFO *) &amp;osvi) ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Return empty string in case of problems<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto next_label;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br>&nbsp; &nbsp;<br>&nbsp; switch (osvi.dwPlatformId)<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; // Test for the Windows NT product family.<br>&nbsp;&nbsp;&nbsp; case VER_PLATFORM_WIN32_NT:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Test for the specific product.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( osvi.dwMajorVersion == 5 &amp;&amp; osvi.dwMinorVersion == 2 )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"WinServer2003, ");<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( osvi.dwMajorVersion == 5 &amp;&amp; osvi.dwMinorVersion == 1 )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"WinXP ");<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( osvi.dwMajorVersion == 5 &amp;&amp; osvi.dwMinorVersion == 0 )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"Win2K ");<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( osvi.dwMajorVersion &lt;= 4 )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"WinNT ");<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Display service pack (if any) and build number.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( osvi.dwMajorVersion == 4 &amp;&amp; lstrcmpi( osvi.szCSDVersion, "Service Pack 6" ) == 0 )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HKEY hKey;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LONG lRet;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Test for SP6 versus SP6a.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWAREMicrosoftWindows NTCurrentVersionHotfixQ246009", 0, KEY_QUERY_VALUE, &amp;hKey );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( lRet == ERROR_SUCCESS ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sprintf(buf2, "SP 6a (Build %d), ", (int)(osvi.dwBuildNumber &amp; 0xFFFF) );&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,buf2);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else // Windows NT 4.0 prior to SP6a<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sprintf(buf2, "%s (Build %d), ",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; osvi.szCSDVersion,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (int)(osvi.dwBuildNumber &amp; 0xFFFF));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,buf2);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RegCloseKey( hKey );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else // not Windows NT 4.0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sprintf(buf2, "%s (Build %d), ", osvi.szCSDVersion, (int)(osvi.dwBuildNumber &amp; 0xFFFF));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,buf2);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Test for the Windows Me/98/95.<br>&nbsp;&nbsp;&nbsp; case VER_PLATFORM_WIN32_WINDOWS:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (osvi.dwMajorVersion == 4 &amp;&amp; osvi.dwMinorVersion == 0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"Win95 ");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"OSR2 " );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (osvi.dwMajorVersion == 4 &amp;&amp; osvi.dwMinorVersion == 10)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"Win98 ");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( osvi.szCSDVersion[1] == 'A' )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"SE " );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (osvi.dwMajorVersion == 4 &amp;&amp; osvi.dwMinorVersion == 90)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"WinME ");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br><br>&nbsp;&nbsp;&nbsp; case VER_PLATFORM_WIN32s:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"Win32s ");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp; }<br>&nbsp; &nbsp;<br>next_label:<br><br>&nbsp; strcat(buf,"on ");<br>&nbsp; // Get and display the name of the computer.<br>&nbsp; bufCharCount = INFO_BUFFER_SIZE;<br>&nbsp; if( !GetComputerName( infoBuf, &amp;bufCharCount ) )<br>&nbsp;&nbsp;&nbsp; goto next_label_2;<br>&nbsp; strcat(buf, infoBuf );<br>&nbsp; <br>next_label_2:<br>&nbsp; strcat(buf," (");<br>&nbsp; if (!(osvi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS &amp;&amp; osvi.dwMajorVersion == 4 &amp;&amp; osvi.dwMinorVersion == 0)) {<br>&nbsp;&nbsp;&nbsp; // Win95 does not keep CPU info in registry<br>&nbsp;&nbsp;&nbsp; LONG lRet;<br>&nbsp;&nbsp;&nbsp; HKEY hKey;<br>&nbsp;&nbsp;&nbsp; char szOrigCPUType[BUFSIZE];<br>&nbsp;&nbsp;&nbsp; int i=0;<br>&nbsp;&nbsp;&nbsp; DWORD dwBufLen=BUFSIZE;<br>&nbsp;&nbsp;&nbsp; lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE, "HARDWAREDESCRIPTIONSystemCentralProcessor", 0, KEY_QUERY_VALUE, &amp;hKey );<br>&nbsp;&nbsp;&nbsp; if( lRet != ERROR_SUCCESS ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto next_label_3;<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; lRet = RegQueryValueEx( hKey, "ProcessorNameString", NULL, NULL, (LPBYTE) szOrigCPUType, &amp;dwBufLen);<br>&nbsp;&nbsp;&nbsp; if( (lRet != ERROR_SUCCESS) || (dwBufLen &gt; BUFSIZE) ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto next_label_3;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; RegCloseKey( hKey );<br><br>&nbsp;&nbsp;&nbsp; if (strlen(szOrigCPUType)&gt;0) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while(szOrigCPUType[i]==' ' &amp;&amp; szOrigCPUType[i]!=0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i++;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,szOrigCPUType+i);<br>&nbsp;&nbsp;&nbsp; } else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto next_label_3;<br>&nbsp; } else {<br>next_label_3:<br>&nbsp;&nbsp; if (processorArchitecture==PROCESSOR_ARCHITECTURE_UNKNOWN)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"unknown_arch");<br>&nbsp;&nbsp; else if (processorArchitecture==PROCESSOR_ARCHITECTURE_INTEL) {<br>&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"Intel ");<br>&nbsp;&nbsp;&nbsp;&nbsp; sprintf(buf2,"level %d ",processorLevel);<br>&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,buf2);<br>&nbsp;&nbsp; } else if (processorArchitecture==PROCESSOR_ARCHITECTURE_IA64)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"IA64 ");<br>&nbsp;&nbsp; else if (processorArchitecture==PROCESSOR_ARCHITECTURE_MIPS)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"MIPS ");<br>&nbsp;&nbsp; else if (processorArchitecture==PROCESSOR_ARCHITECTURE_ALPHA)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"Alpha ");<br>&nbsp;&nbsp; else if (processorArchitecture==PROCESSOR_ARCHITECTURE_PPC)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"PowerPC ");<br>&nbsp;&nbsp; else if (processorArchitecture==PROCESSOR_ARCHITECTURE_SHX)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"SHX ");<br>&nbsp;&nbsp; else if (processorArchitecture==PROCESSOR_ARCHITECTURE_ALPHA64)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"Alpha64 ");<br>&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(buf,"unknown_arch ");<br>&nbsp; }<br>&nbsp; <br>&nbsp; strcat(buf,")");<br><br>&nbsp; retval = (*env)-&gt;NewStringUTF(env,buf);<br>&nbsp; return retval;<br>}<br>/* ......................................................................... */<br><br><br><br><br><br><br>#undef MIN_ELAPSED_TIME<br><br>/* ------------------------------------------------------------------------- */<br>/* end of file */<br><br><br><br><br><br>编写makefile<br>#&nbsp;&nbsp;&nbsp; Project: SystemInfo<br>#&nbsp;&nbsp;&nbsp; Makefile created by Khan.Lau<br>#&nbsp;&nbsp;&nbsp; Write&nbsp;&nbsp;&nbsp; by 2007-05-16<br><br><br>#&nbsp;&nbsp;&nbsp; 应用程序名<br>#LIB = SystemInfo.a<br>DLL =&nbsp;&nbsp;&nbsp; SystemInfo.dll<br>#BIN = SystemInfo.exe<br><br><br>#&nbsp;&nbsp;&nbsp; 输出目录<br>#&nbsp;&nbsp;&nbsp; CONFIGURATION = debug<br>CONFIGURATION&nbsp;&nbsp;&nbsp; =&nbsp;&nbsp;&nbsp; release<br><br>#&nbsp;&nbsp;&nbsp; 取得项目的当前工作路径<br>PROJECT_PATH = "D:/Project/Cplus/SystemInfo/src"<br><br>CPP = g++<br>CC = gcc<br>COMPILER = $(CC)<br><br>#&nbsp;&nbsp;&nbsp; c/c++库路径<br>LIBPATH = "D:/Develop/CPlus/MinGW/lib"<br><br>WINDRES = windres.exe<br>RES =<br><br>#&nbsp;&nbsp;&nbsp; 包路径<br>LIBS = -L$(LIBPATH) \<br>&nbsp;&nbsp;&nbsp; -lpsapi<br><br>INCS = -I$(LIBPATH)/include \<br>&nbsp;&nbsp;&nbsp; -ID:/Develop/Java/jdk1.5.0_02/include \<br>&nbsp;&nbsp;&nbsp; -ID:/Develop/Java/jdk1.5.0_02/include/win32 \<br>&nbsp;&nbsp;&nbsp; -I$(PROJECT_PATH)<br><br>CXXINCS = -I$(LIBPATH)/include \<br>&nbsp;&nbsp;&nbsp; -I$(LIBPATH)/include/c++/3.2.3 \<br>&nbsp;&nbsp;&nbsp; -I$(LIBPATH)/include/c++/3.2.3/backward \<br>&nbsp;&nbsp;&nbsp; -I$(LIBPATH)/include/c++/3.2.3/mingw32 \<br>&nbsp;&nbsp;&nbsp; -I$(PROJECT_PATH)<br><br>DLLFLAGS = -DBUILD_DLL<br>CXXFLAGS = $(DLLFLAGS) -g -Wall $(CXXINCS)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>CFLAGS = $(DLLFLAGS) -Wall $(INCS)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br><br>COMPILER_FLAG = $(CFLAGS)<br><br>RM = rm -f<br><br>LINKOBJ = $(CONFIGURATION)/SystemInfo.o&nbsp;&nbsp;&nbsp; \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(RES)<br><br><br>.PHONY:&nbsp;&nbsp;&nbsp; all all-before all-after clean clean-custom rebuild&nbsp; &nbsp;<br><br>all: all-before $(DLL) all-after<br><br>clean: clean-custom<br>&nbsp;&nbsp;&nbsp; ${RM} $(LINKOBJ) $(CONFIGURATION)/$(DLL)&nbsp; &nbsp;<br><br>$(LIB): $(LINKOBJ)<br>&nbsp;&nbsp;&nbsp; ar -r $(CONFIGURATION)/$(LIB) $(LINKOBJ)&nbsp; &nbsp;<br><br>$(DLL): $(LINKOBJ)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(COMPILER)&nbsp; -shared -Wl,--add-stdcall-alias&nbsp; -o $(CONFIGURATION)/$(DLL) $(LINKOBJ) $(LIBS)<br><br>$(BIN):&nbsp;&nbsp;&nbsp; $(LINKOBJ)<br>&nbsp;&nbsp;&nbsp; $(COMPILER) -o $(CONFIGURATION)/$(BIN) $(LINKOBJ) $(LIBS)<br><br>#缩减可执行文件大小<br>strip:&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp; strip&nbsp;&nbsp;&nbsp; $(CONFIGURATION)/$(LIB)<br>&nbsp; &nbsp;<br><br>################################################################################<br><br>$(CONFIGURATION)/SystemInfo.o: src/dll/SystemInfo.c<br>&nbsp;&nbsp;&nbsp; $(COMPILER) -c src/dll/SystemInfo.c -o $(CONFIGURATION)/SystemInfo.o $(COMPILER_FLAG)<br><br><br>################################################################################<br><br>rebuild: clean&nbsp;&nbsp;&nbsp; all<br><br><br><br>makefile中注意<br>$(DLL): $(LINKOBJ)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(COMPILER)&nbsp; -shared -Wl,--add-stdcall-alias&nbsp; -o $(CONFIGURATION)/$(DLL) $(LINKOBJ) $(LIBS)<br><br>-shared -Wl,--add-stdcall-alias 这3个参数是一定要的. 具体含义请参阅gcc帮助..<br>否则会出现如下异常:java.lang.UnsatisfiedLinkError<br>如果你确认自己的dll名没有错. loadlibrary的名字也没有填错. 那应该就要检查如上部分了<br><br>实际发布的时候. 不要使用调试版本. 也就是编译参数不能有-g<br><br>ok, 现在make出dll使用吧....<br><br><br>我本地测试的输出结果为 :<br><br>getMaxMem:506604<br>getCPUs:1<br>getSysInfo:WinXP Service Pack 2 (Build 2600), on A7648944D08843B (Intel level 15 )<br>SystemInfo.dll is Loaded<img src ="http://www.cppblog.com/Khan/aggbug/54364.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Khan/" target="_blank">Khan's Notebook</a> 2008-06-23 12:57 <a href="http://www.cppblog.com/Khan/archive/2008/06/23/54364.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ubuntu 下安装wine</title><link>http://www.cppblog.com/Khan/archive/2008/05/23/50909.html</link><dc:creator>Khan's Notebook</dc:creator><author>Khan's Notebook</author><pubDate>Fri, 23 May 2008 15:18:00 GMT</pubDate><guid>http://www.cppblog.com/Khan/archive/2008/05/23/50909.html</guid><wfw:comment>http://www.cppblog.com/Khan/comments/50909.html</wfw:comment><comments>http://www.cppblog.com/Khan/archive/2008/05/23/50909.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Khan/comments/commentRss/50909.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Khan/services/trackbacks/50909.html</trackback:ping><description><![CDATA[编译源码的方式就不写了， 无非就是解决依赖关系， down一堆的包， 然后make<br>简单粗暴的来......<br><br>1.安装<br>sudo apt-get install <span class="hilite1">wine<br><br>2.初始化<br>winecfg&nbsp; //不要用root模式, 也就是不要用sudo<br><br>如果出现以下警告或者错误:<br></span><span class="postbody">preloader: Warning: failed to reserve range 00000000-60000000
<br>
err:dosmem:setup_dos_mem Cannot use first megabyte for DOS address space, please report
</span><br><br>解决方法: 其实我不清楚为什么要这么做....唉.....<br><span class="postbody">sudo sysctl -w vm.mmap_min_addr=0
<br>
<br>
然后打开sysctl.conf
<br>
sudo gedit /etc/sysctl.conf
<br>
<br>
#vm.mmap_min_addr = 65536&nbsp;
//注释掉这行<br>
vm.mmap_min_addr = 0&nbsp;
//改为这行</span><br><span class="hilite1"><br><br></span>
<p>3、设置中文问题</p>
<p>&nbsp;&nbsp; 先把字体simsun.ttc（在你的windows的<span class="hilite2">安装</span>目录里的font文件夹里找，找不到可以从网上下到） 复制到 /home/你的用户名/.<span class="hilite1">wine</span>/drive_c/windows/fonts 文件夹中，<span style="color: #ff0000; font-size: small;">要显示隐藏文件夹按Ctrl+H</span>
</p>
<br>
<p>&nbsp; 修改注册表，在命令行输入 gedit&nbsp; ~/.<span class="hilite1">wine</span>/system.reg</p>
<p>&nbsp; 找到&#8220;[System\\CurrentControlSet\\Hardware
Profiles\\Current\\Software\\Fonts]&#8221;，将其中的&#8220;&#8220;LogPixels&#8221;=dword:00000060&#8221;改成
&#8220;&#8220;LogPixels&#8221;=dword:00000070&#8220;。<br>
<br>
再找到&#8221;[Software\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes] xxxx&#8220;项，将其中的&#8221;MS Shell Dlg&#8220;相关的两项修改成如下内容（即更换字体为宋体）：<br>
<br>
&#8220;MS Shell Dlg&#8221;=&#8221;SimSun&#8221;<br>
&#8220;MS Shell Dlg 2&#8243;=&#8221;SimSun&#8221;<br>
<br>
然后：gedit ~/.<span class="hilite1">wine</span>/drive_c/windows/win.ini</p>
<p>在其中加上（如果没有），有的话修改成如下</p>
<p> [Desktop]<br>
menufontsize=13<br>
messagefontsize=13<br>
statusfontsize=13<br>
IconTitleSize=13</p>
<p>现在中文显示应该正常了</p>
<br><span class="hilite1"><br></span><img src ="http://www.cppblog.com/Khan/aggbug/50909.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Khan/" target="_blank">Khan's Notebook</a> 2008-05-23 23:18 <a href="http://www.cppblog.com/Khan/archive/2008/05/23/50909.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>