ѧϰlinux programming(1)
¡¾1. linux applications ÓÐÁ½ÖÖÐÎʽ¡¿
i£©¿ÉÖ´ÐеÄÎļþ£º ¿ÉÓɼÆËã»úÖ±½ÓÔËÐУ¬Ï൱ÓÚwindowsµÄ.exeÎļþ
ii£©Script: collections of instructions for another program. Ï൱ÓÚwindowsµÄ.bat .cmdÎļþ
¡¾2. PATH¡¿
ÔÚLinuxÖУ¬µ±ÊäÈë³ÌÐòÃû£¨ÈçFirefox£©Ê±£¬ÏµÍ³»áÔÚÃûΪPATHµÄShell±äÁ¿Ëù¸ø¶¨µÄһϵÁÐĿ¼ÖÐѰÕÒÊÇ·ñÓÐͬÃûµÄÎļþ¡£
²é¿´PATHµÄÖµ£¬ÔÚLinux£º $PATH »òÕß echo $PATH
windows£º PATH
Linux¿ÉÖ´ÐÐÎļþλÖÃ˵Ã÷£º
/bin: binaries, programs used in booting the system
/usr/bin: user binaries, standard programs available to users
/usr/local/bin: local binaries, programs specific to an installation
µ±ÒÔadministatorÉí·Ý½øÈëʱ£¬¿ÉÄÜ»áʹÓÃϵͳ¹ÜÀí³ÌÐòËùÔÚµÄPATHĿ¼£¬Èç: /sbin »ò /usr/sbin
Linux£¬like unix, ÔÚPATH±äÁ¿µÄentriesÖ®¼äÓÃcolon(:)·Ö¸ô£¬¶øwindowsºÍms-dosÓÃsemicolon (;) ·Ö¸ô¡£
Linux£ºÊ¹ÓÃforward slash (/) À´·Ö¸ôĿ¼
eg: /usr/bin/
windows: ʹÓÃbackward slash (\)À´·Ö¸ô
eg: c:\Documents and settings\user>
¡¾3. C compiler¡¿
ÔÚPOSIX-compliant system (POSIX: Portable Operating System Interface), C compiler is called c89.
in linux, c89, cc, gcc refer to the system c compiler.
¡¾4. first c program in linux¡¿
1) hello.c file content
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello World!\n");
}
2) compile
$gcc -o hello hello.c
gcc²ÎÊý˵Ã÷£º
-o <file>£ºÊä³öµ½file,Èôδָ¶¨-o£¬ÔòdefaultÊä³öµ½a.out
Èç¹ûÒª²é¿´ÖмäÉú³ÉÎļþ£¬¿ÉÓÃgcc²ÎÊý -save-temps
$gcc -save-temps -o hello hello.c
$ls
hello hello.c hello.i hello.o hello.s
//ÒÔÉÏÉú³ÉµÄ4¸öÎļþ˵Ã÷¼û¡¾5.±àÒëϵͳ¡¿
3) execute
$./hello
˵Ã÷£º
ÈôÖ±½ÓÓÃhello£¬¼´Ö´ÐÐ
$hello
Ôòϵͳ»áÔÚShell±äÁ¿PATHËùÁгöµÄĿ¼ÖÐsearch£¬ÈôÇ¡ºÃÓÐÒ»¸öÃûΪ
helloµÄÎļþ£¬ÔòÖ´ÐÐÖ®¡£
./£º ´ú±íµ±Ç°Ä¿Â¼¡£
¡¾5.±àÒëϵÍ
Ïà¹ØÎĵµ£º
ÔÚWindowsÖпÉÒÔÔÚijЩ·¾¶ÖвéÕÒÎļþ£¬Ò²¿ÉÒÔÉ趨²»ÔÚijЩ·¾¶ÖвéÕÒÎļþ£¬ÏÂÃæÓÃLinuxÖеÄfindµÄÃüÁî½áºÏÆä-path -prune²ÎÊýÀ´¿´¿´ÔÚLinuxÖÐÔõôʵÏִ˹¦ÄÜ¡£
¼ÙÈçÔÚµ±Ç°Ä¿Â¼Ï²éÕÒÎļþ£¬ÇÒµ±Ç°Ä¿Â¼ÏÂÓкܶàÎļþ¼°Ä¿Â¼£¨¶à²ãĿ¼£©£¬°üÀ¨dir0¡¢dir1ºÍdir2 ...µÈĿ¼¼°dir00¡¢dir01...dir10¡¢dir11...µÈ×ÓĿ¼¡£
......
ÔÚLinuxÀïÃæÒ»ÇнÔÎļþ£¬´ÓÎļþѧÆðÀ´£¬×î³£¼ûµÄÃüÁî¾ÍÊDz鿴ÎļþºÍËÑË÷Îļþ¡£
ÏÂÃæ¼òµ¥µÄ×ܽáÏÂÕ⼸¸öÃüÁ
²é¿´Îļþ(cat,tac,more,less,head,tail,od)
cat:
cat [file]
²é¿´ÎļþµÄÄÚÈÝ¡£È«³ÌʽconcatenateµÄÒâ˼£¬½«ÎļþÄÚÈÝÁ¬ÐøÊä³öµ½ÆÁÄ»ÉÏ¡£µÚÒ»Ðе½×îºóÒ»ÐÐÏÔʾ¡£
tac:
tac [file]
ºÍcat¸ÕºÃÏà·´ ÊÇ´Ó ......
Linux
¶àÏ̱߳à³Ì£º¡¾
http://fanqiang.chinaunix.net/a4/b8/20010811/0905001105.html
¡¿
Linux
¶àÏß³ÌÖ§³Ö
POSIX
Ï߳̽ӿڣ¬³ÆÎª
pthread,
pthread_create
ÓÃÀ´´´½¨Ị̈߳¬
pthread_join
µÈ´ýÏ߳̽áÊø£¬º¯ÊýµÄÔÐÍ·Ö±ðÈçÏ£º
&nbs ......
Ò» ¡¢LinuxÎļþ½á¹¹
¡¡¡¡Îļþ½á¹¹ÊÇÎļþ´æ·ÅÔÚ´ÅÅ̵ȴæÖüÉ豸ÉϵÄ×éÖ¯·½·¨¡£Ö÷ÒªÌåÏÖÔÚ¶ÔÎļþºÍĿ¼µÄ×éÖ¯ÉÏ¡£
¡¡¡¡Ä¿Â¼ÌṩÁ˹ÜÀíÎļþµÄÒ»¸ö·½±ã¶øÓÐЧµÄ;¾¶¡£
¡¡¡¡LinuxʹÓñê×¼µÄĿ¼½á¹¹£¬ÔÚ°²×°µÄʱºò£¬°²×°³ÌÐò¾ÍÒѾΪÓû§´´½¨ÁËÎļþϵͳºÍÍêÕû¶ø¹Ì¶¨µÄĿ¼×é³ÉÐÎʽ£¬²¢Ö¸¶¨ÁËÿ¸öĿ¼µÄ×÷ÓÃºÍÆäÖеÄÎļþÀàÐÍ ......