linux fork() º¯ÊýʵÀýÏê½â
forkº¯Êýѧϰ£º
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
main ()
{
pid_t pid; pid=fork();
if (pid < 0)
printf("error in fork!");
else if (pid == 0)
printf("i am the child process, my process id is %dn",getpid());
else
printf("i am the parent process, my process id is %dn",getpid());
}
Õâ¶Î´úÂëдÁËÒ»¸öʹÓÃforkº¯Êý´´½¨×Ó½ø³Ì£¬¸¸×Ó½ø³ÌͬʱÔËÐжø²úÉú½»´íµÄ£¬²»Ò»ÑùµÄÔËÐнá¹û¡£ÔËÐнá¹ûÈçÏ£º
# ./a.out
i am the child process, my process id is 4286
i am the parent process, my process id is 4285
forkÔÚÓ¢ÎÄÖÐÊDzæ×Ó£¬·Ö²æµÄÒâ˼£¬ÔÚº¯ÊýforkÖУ¬È¡ºóÃæµÄÒâ˼¡£ºÜÐÎÏóµÄ±íʾ³ÌÐò´ÓÕâÀï·Ö²æ£¬forkº¯Êý´´½¨ÁË×Ó½ø³Ì£¬×Ó½ø³ÌºÍ¸¸½ø³Ìͬʱ£¨ÆäʵÊÇcpu·Öʱ´¦Àí£©¿ªÊ¼ÔËÐзֲæÖ®ºóµÄ³ÌÐò¡£
³ÌÐò¸ÄдÏ£º
main()
{
pid_t pid;
printf("\n[%d]not fork pid=%d\n",getpid(),pid);
pid=fork();
printf("\n[%d]forked pid=%d\n",getpid(),pid);
if(pid<0)
{
printf("error in fork!\n");
getchar();
exit(1);
}
else if(pid==0)
printf("\n[%d]in child process,p_id=%d\n",getpid(),getpid());
else
{
printf("\n[%d]in parent process,my pid=%d\n",getpid(),pid);
printf("\n[%d]in parent process,my getpid=%d\n",getpid(),getpid());
}
}
³ÌÐòÔËÐнá¹ûÈçÏ£º
$ ./fork
[3819]not fork
[3820]forked pid=0
[3820]in child process,p_id=3820
[3819]forked pid=3820
[3819]in parent process,my pid=3820
[3819]in parent process,my getpid=3819
¿ÉÒÔÇå³þµÄ¿´µ½ not forkÖ»´òÓ¡ÁËÒ»´Î£¬ÆäÖÐ[3819]ÊǸ¸½ø³ÌµÄ½ø³ÌºÅ£¬´´½¨forkÒÔºó£¬forkº¯Êý·µ»Ø¸ø¸¸½ø³ÌµÄÖµpidÊÇ×Ó½ø³ÌµÄ½ø³ÌºÅ[3820]£¬¶øÔÚ×Ó½ø³ÌÖУ¬pidֵΪÁã¡£Ò²¾ÍÊÇ˵×Ó½ø³ÌÖУ¬pid±»ÖÃÁã¡£ ÒýÓÃÍøÉÏÒ»Î»ÍøÓѵĽâÊÍ“Æäʵ¾ÍÏ൱ÓÚÁ´±í£¬½ø³ÌÐγÉÁËÁ´±í£¬¸¸½ø³Ìpid(p Òâζpoint)Ö¸Ïò×Ó½ø³ÌµÄ½ø³
Ïà¹ØÎĵµ£º
Ò»£ºÇ°ÑÔ
×î½üÔÚÑо¿androidµÄsensor driver£¬Ö÷ÒªÊÇE-compass£¬ÆäÖÐÓõ½ÁËLinux input×Óϵͳ.ÔÚÍøÉÏÒ²¿´Á˺ܶàÕâ·½ÃæµÄ×ÊÁÏ£¬¸Ð¾õ»¹ÊÇÕâÆª·ÖÎöµÄ±È½ÏϸÖÂ͸³¹£¬Òò´Ë×ªÔØÒ»ÏÂÒÔ±ã×Ô¼ºÑ§Ï°£¬Í¬Ê±ºÍ´ó¼Ò·ÖÏí£¡
£¨ÕâÆª²©¿ÍÖ÷ÒªÊÇÒÔ¼üÅÌÇý¶¯ÎªÀýµÄ£¬²»¹ý½²½âµÄÊÇLinux Input Subsystem£¬¿ÉÒÔ×ÐϸµÄÑо¿Ò»Ï£¡£©
¼üÅÌÇý¶¯½«¼ì ......
¡¡¡¡±¾ÎÄÒ²¼´¡¶Learning the bash Shell¡·3rd EditionµÄµÚÈýÕÂCustomizing Your EnvironmentÖ®¶ÁÊé±Ê¼Ç£¬µ«ÎÒÃǽ«²»ÏÞÓÚ´Ë¡£ÉèÖÃÒ»¸öºÃµÄÓû§»·¾³£¬¶ÔÎÒÃÇ¿ª·¢ÊǷdz£¹Ø¼üµÄ¡£ÔÚÕâÒ»Õ½ÚÖУ¬´ÓËĸö·½Ãæ½øÐнéÉÜ£ºÌرðµÄÎļþ£¬±ðÃû£¬Ñ¡Ï²ÎÊý¡£
ÌØÊâÎļþ
¡¡¡¡ÔÚÓû§Ä¿Â¼ÏÂÓм¸¸öÌØÊâµÄÎļþ£¬¿ÉÒÔÓÃls -a
À´²é¿´ÕâЩÒþ² ......
.tar
½â°ü£º tar xvf FileName.tar
´ò°ü£ºtar cvf FileName.tar DirName
£¨×¢£ºtarÊÇ´ò°ü£¬²»ÊÇѹËõ£¡£©
---------------------------------------------
.gz
½âѹ1£ºgunzip FileName.gz
½âѹ2£ºgzip -d FileName.gz
ѹËõ£ºgzip FileName
.tar.gz
½âѹ£ºtar zxvf FileName.tar.gz
ѹËõ£ºtar zcvf FileName.tar ......
ά»¤LinuxµÄssh¹¤¾ßÔÚʹÓÃÖУ¬Ò»µ©Óöµ½ÍøÂçÖжϣ¬Ôòµ±Ç°µÄshell¾Í»á×Ô¶¯¹Ø±Õ
µ±Ç°µÄ¹¤×÷½ø¶È¾Í»á¶ªÊ§£¬Õâ¶ÔÓÚÔ¶³ÌÉý¼¶µÈ±È½ÏºÄ·Ñʱ¼äµÄ¹¤×÷ÊǷdz£²»ÀûµÄ
¶ÔÓÚÔ¶³Ìµ÷ÊÊ´úÂëÒ²ÊǺܲ»¿É¿¿²»°²È«µÄ
Ϊ´Ë£¬¿ÉÒÔʹÓÃscreenÕâ¸ö¹¤¾ßÀ´½â¾öÕâ¸öÎÊÌâ¡£
¶ÔÓÚ×îС»¯µÄlinux£¬Í¨³£screenÊDz»°üº¬ÔÚϵͳÄڵġ£
ÐèÒª²éÕÒ²Ù×÷ϵͳµÄ°² ......