°²×¿ÏµÍ³ÓëLinuxÄں˵ÄÉñÃؽÒÃØ
°²×¿ÏµÍ³ÓëLinuxÄں˵ÄÉñÃؽÒÃØ
Ëæ×ÅÖÇÄÜÊÖ»úµÄÆÕ¼°ºÍÒƶ¯»¥ÁªÍøµÄÉú³¤£¬°²×¿ÏµÍ³×÷Ϊ×îÖ÷Á÷µÄÊÖ»ú²Ù×÷ϵͳ֮һ£¬±¸ÊܹØ×¢¡£¶ø×÷Ϊ°²×¿ÏµÍ³µÄÄںˣ¬LinuxÄÚºËÔòÊÎÑÝ×ÅÖÁ¹ØÖ÷ÒªµÄ½ÇÉ«¡£±¾ÎĽ«Ì½ÌÖ°²×¿ÏµÍ³ÓëLinuxÄں˵ĹØϵ¼°ÆäÄÚÔÚÉñÃØ£¬²¢¸ø³öһЩÏêϸµÄ´úÂëʾÀý¡£
°²×¿ÏµÍ³ÓëLinuxÄں˵ĹØϵ
°²×¿ÏµÍ³ÊÇ»ùÓÚLinuxÄں˵ĿªÔ´²Ù×÷ϵͳ£¬Í¨¹ýÌí¼ÓÓ¦ÓóÌÐò¿ò¼Ü¡¢Óû§½çÃæµÈ×é¼þ¶ø¹¹½¨¶ø³É¡£Òò´Ë£¬°²×¿ÏµÍ³¼ÌÐøÁËLinuxÄں˵ÄÎȹÌÐÔ¡¢Çå¾²ÐԺ͸ßЧÐÔ£¬²¢ÔÚ´Ë»ù´¡ÉϼÓÈëÁËÐí¶à¶¨ÖÆ»¯µÄ¹¦Ð§£¬ÒÔÖª×ãÊÖ»úµÈÒƶ¯×°±¸µÄÐèÇó¡£
LinuxÄÚºË×÷Ϊ°²×¿ÏµÍ³µÄµ×²ã½¹µã£¬ÈÏÕæÖÎÀí×°±¸Çý¶¯¡¢ÄÚ´æÖÎÀí¡¢Àú³ÌÖÎÀíµÈϵͳµÄ»ù±¾ÔËÐС£°²×¿ÏµÍ³ÔÚLinuxÄں˵Ļù´¡ÉÏ£¬¼ÓÈëÁËAndroid Runtime¡¢Ó¦ÓóÌÐò¿ò¼ÜµÈ×é¼þ£¬Ê¹µÃ°²×¿ÏµÍ³Äܹ»ÊµÏÖ¸ü¶à¸ß¼¶¹¦Ð§ºÍЧÀÍ¡£
°²×¿ÏµÍ³ÓëLinuxÄں˵ÄÄÚÔÚÉñÃØ
°²×¿ÏµÍ³ÓëLinuxÄÚºËÖ®¼äÓÐÐí¶àÒþ²ØµÄÄÚÔÚÉñÃØ£¬ÆäÖÐ×îÖ÷ÒªµÄÒ»µã¾ÍÊÇ°²×¿ÏµÍ³¶ÔLinuxÄں˵ÄÉî¶È¶¨ÖÆ¡£°²×¿ÏµÍ³¶ÔLinuxÄں˾ÙÐÐÁËÐí¶àÐ޸ĺÍÓÅ»¯£¬ÒÔ˳ӦÒƶ¯×°±¸µÄÌØÊâÐèÇó¡£
ÏêϸÀ´Ëµ£¬°²×¿ÏµÍ³ÔÚLinuxÄں˵Ļù´¡ÉÏ£¬Ìí¼ÓÁËÐí¶àеÄÇý¶¯£¬µ÷½âÁËÄÚ´æÖÎÀíÕ½ÂÔ£¬ÓÅ»¯ÁËÀú³ÌÖÎÀí»úÖƵȡ£ÕâЩ¸Ä¶¯Ê¹µÃ°²×¿ÏµÍ³Äܹ»¸üºÃµØ˳ӦÊÖ»úµÄʹÓó¡¾°£¬Ìṩ¸üºÃµÄÓû§ÌåÑé¡£
´úÂëʾÀý
½ÓÏÂÀ´£¬ÎÒÃǽ«¸ø³öһЩÏêϸµÄ´úÂëʾÀý£¬ÒÔչʾ°²×¿ÏµÍ³ÔõÑùÓëLinuxÄں˾ÙÐн»»¥¡£
ʾÀý1£ºÍ¨¹ýprocÎļþϵͳ»ñÈ¡LinuxÄÚºËÐÅÏ¢
public void getKernelInfo() { try { File file = new File("/proc/version"); FileInputStream fis = new FileInputStream(file); BufferedReader br = new BufferedReader(new InputStreamReader(fis)); String line = br.readLine(); Log.d("Kernel Info", line); } catch (Exception e) { Log.e("Error", e.getMessage()); } }
µÇ¼ºó¸´ÖÆ
ʾÀý2£ºÅ²ÓÃLinuxÄں˽ӿھÙÐÐ×°±¸Çý¶¯²Ù×÷
public void controlDevice() { File file = new File("/dev/mydevice"); FileInputStream fis = new FileInputStream(file); // ¶Áȡװ±¸Êý¾Ý byte[] data = new byte[1024]; fis.read(data); // дÈë×°±¸Êý¾Ý FileOutputStream fos = new FileOutputStream(file); byte[] newData = "Hello, device!".getBytes(); fos.write(newData); }
µÇ¼ºó¸´ÖÆ
ͨ¹ýÒÔÉÏ´úÂëʾÀý£¬ÎÒÃÇ¿ÉÒÔ¿´µ½°²×¿ÏµÍ³ÊÇÔõÑùͨ¹ýÎļþϵͳºÍϵͳŲÓÃÓëLinuxÄں˾ÙÐн»»¥µÄ¡£ÕâЩ´úÂëչʾÁË°²×¿ÏµÍ³ÓëLinuxÄÚºËϸÃÜÍŽáµÄ·½·¨£¬ÌåÏÖÁËËüÃÇÖ®¼äÖØ´ó¶øÓÖÇ×½üµÄ¹Øϵ¡£
×ܽ᣺°²×¿ÏµÍ³ÓëLinuxÄں˵ÄÉñÃØÊÇÒ»¸öÁÉÀ«µÄÁìÓò£¬Éæ¼°µ½Ðí¶àµ×²ãÔÀíºÍÊÖÒÕ¡£Í¨¹ý±¾ÎĵÄ̽ÌÖ£¬ÎÒÃǶ԰²×¿ÏµÍ³ÓëLinuxÄں˵ĹØϵÓÐÁ˸üÉîÈëµÄÏàʶ£¬Í¬Ê±Ò²Õ¹Ê¾ÁËËüÃÇÖ®¼ä½»»¥µÄһЩÏêϸ´úÂëʾÀý¡£Ï£Íû¶ÁÕßÄܹ»½øÒ»²½Ì½Ë÷Õâ¸öÁìÓò£¬ÉîÈëÏàʶ°²×¿ÏµÍ³ÓëLinuxÄÚºËÖ®¼äµÄ¸»ºñÄÚÔÚ¡£
ÒÔÉϾÍÊÇ°²×¿ÏµÍ³ÓëLinuxÄں˵ÄÉñÃؽÒÃصÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡