Javaµ÷ÓÃLinuxÃüÁîÐÐÈô¸ÉʵÀý
Executing a CommandSee also e90 Reading Output from a Command.
try {
// Execute a command without arguments
String command = "ls";
Process child = Runtime.getRuntime().exec(command);
// Execute a command with an argument
command = "ls /tmp";
child = Runtime.getRuntime().exec(command);
} catch (IOException e) {
}
If an argument contain spaces, it is necessary to use the overload that requires the command and its arguments to be supplied in an array:
try {
// Execute a command with an argument that contains a space
String[] commands = new String[]{"grep", "hello world", "/tmp/f.txt"};
commands = new String[]{"grep", "hello world", "c:\\Documents and Settings\\f.txt"};
Process child = Runtime.getRuntime().exec(commands);
} catch (IOException e) {
}
e90. Reading Output from a Commandtry {
// Execute command
String command = "ls";
Process child = Runtime.getRuntime().exec(command);
// Get the input stream and read from it
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
process((char)c);
}
in.close();
} catch (IOException e) {
}
e91. Sending Input to a Commandtry {
// Execute command
String command = "cat";
Process child = Runtime.getRuntime().exec(command);
// Get output stream to write from it
OutputStream out = child.getOutputStream();
out.write("some text".getBytes());
out.close();
} catch (IOException e) {
}
Ïà¹ØÎĵµ£º
ÕûÀíÁËһЩ³£ÓõÄLinuxÃüÁî
http://jythoner.javaeye.com/blog/290976
¹Ø¼ü×Ö: linux
1.²é¿´ÏµÍ³ÄÚºË
#uname -a
2.²é¿´cpuÐÅÏ¢
#cat /proc/cpuinfo
3.²é¿´ÄÚ´æÊ¹ÓÃÇé¿ö
#free -m
4.²é¿´Ó²ÅÌÊ£Óà¿Õ¼ä
#df -h
5.²é¿´Ä¿Â¼Õ¼Óÿռä
#du -hs Ŀ¼Ãû
6.²é¿´µ±Ç°ÓÐÄÄЩ½ø³Ì
#ps -A
7.²é¿´µ±Ç°½ø³ÌµÄʵ ......
ÏîÄ¿Öг£Óöµ½ÐèÒª¶ÔĿǰÔËÐеÄϵͳ½øÐÐЧÂÊ·ÖÎö£¬»òÅöµ½¿Í»§×ÉѯÈçºÎÓÅ»¯ÏµÍ³µÄЧÂÊÎÊÌâ¡£¸ü¶àµÄÇé¿öÊÇ£¬ÔÚϵͳ³öÏÖÎÊÌâµÄʱºò£¬ÐèÒª·ÖÎöÔÒò£¬¶¨Î»ÏµÍ³¹ÊÕÏ»òÆ¿¾±£¬µ±È»£¬×îºÃÊÇ¿ÉÒÔÒ»²¢½â¾ö¹ÊÕÏ¡£µ«Êµ¼ÊÉÏ£¬²Ù×÷ϵͳÓÅ»¯ÊÇÒ»¸ö·Ç³£¸´ÔÓµÄÎÊÌ⣬¿öÇÒlinuxÓÐ×Ô¼ºÒ»Ì×ÓбðÓÚÆäËû²Ù×÷ϵͳ¹ÜÀíµÄ»úÖÆ£¬ÓÉ´Ë»áÒýÆðºÜ¶à²»±ØÒªµÄÎ ......
Èý¡¢VMAºÍPAGE½á¹¹ ºÍmmapº¯Êý
1.page Ö÷Òª³ÉÔ±
atomic_t count;
//Õâ¸öÒ³µÄÒýÓÃÊý. µ±Õâ¸ö count µôµ½ 0, ÕâÒ³±»·µ»Ø¸ø¿ÕÏÐÁбí.
void *virtual;
//Èç¹ûÒ³±»Ó³É䣬Ôò±íʾÕâÒ³µÄÄÚºËÐéÄâµØÖ·; ·ñÔò, NULL.
unsigned long flags;
//ÃèÊöҳ״̬µÄÒ»Ì×λ±êÖ¾. ÕâЩ°üÀ¨ ......
´ÅÅÌÓëĿ¼µÄÈÝÁ¿
ÔÚÎÄ×Ö½Ó¿Úµ×ϲ鿴ĿǰµÄ´ÅÅÌ×î´óÈÝÐíÈÝÁ¿¡¢ÒѾʹÓõôµÄÈÝÁ¿¡¢ ĿǰËùÔÚĿ¼µÄÒÑʹ
ÓÃÈÝÁ¿
Ö¸Áî df [-ahikHTm] [Ŀ¼»òÎļþÃû]
-a £ºÁгöËùÓеÄÎļþϵͳ£¬°üÀ¨ÏµÍ³ÌØÓÐµÄ /proc µÈÎļþϵͳ£»
-k £ºÒÔ KBytes µÄÈÝÁ¿ÏÔʾ¸÷Îļþϵͳ£»
-m £ºÒÔ MBytes µÄÈÝÁ¿ÏÔʾ¸÷Îļþϵͳ£»
......
ps -ef|grep tomcat ²é¿´ÕýÔÚÆô¶¯µÄÏß³Ì
cd .. ÍË»ØÉÏÒ»¼«
ls Áгöµ±Ç°Ä¿Â¼µÄÎļþ
kill -9 [Ï̺߳Å] ¹Ø±ÕÏß³Ì
su - root µÇ½Õ˺Å
ÔĶÁ(0)| ÆÀÂÛ(14)| ·ÖÏí(0) ½ÏÐÂһƪ:ת£º´øËÑË÷·ÖÒ³µÄgird ½Ï¾Éһƪ:·è×Ó ÆÀÂÛ| ÔÞ
ÖÜ˧ 2010-01-26 18:23
su - root µÇ½Õ˺Å
ÖÜ˧ 2010-01-26 19:53
......