锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
{
echo in fnction: $0 $1 $2
var1="in function"
echo var1: $var1
}
var1="outside function"
echo var1: $var1
echo $0: $1 $2
afunc funcarg1 funcarg2
echo var1: $var1
echo $0: $1 $2
OUTPUT:
./ascript: arg1 arg2
in fnction: ./ascript funcarg1 funcarg2
var1: in function
var1: in function
./ascript: arg1 arg2
璇存槑var1鍦╝func鍐呴儴琚敼鍙樹簡銆俿hell鐨勫眬閮ㄥ彉閲忚窡c璇█鏈変簺宸埆錛岃繖閲岄粯璁ゆ墍鏈夊閮ㄥ畾涔夌殑鍙橀噺錛屽湪鍑芥暟鍐呴儴鍙互璁塊棶騫朵笖鍙互鏀瑰彉銆傚嵆澶栭儴瀹氫箟鐨勫彉閲忛粯璁や負鍏ㄥ眬鍙橀噺銆?br />鑻ユ兂鍦╝func鍐呴儴瀹氫箟涓涓眬閮ㄥ彉閲忥紝鍒欓渶瑕佹樉寮忕殑鍔犱笂local var1.
寰呯畫
]]>
1.寮浜嗕竴涓猻tate[50][42]鏁扮粍鍦╩ain鍑芥暟閲岄潰錛岀粨鏋滄彁浜や箣鍚庡彂鐜皉untime error錛岃鐫鏄爢鏍堟孩鍑轟簡銆傜獊鐒舵兂璧鋒潵50*42>2000錛岃繖縐嶆暟緇勪竴瀹氭槸寮鍦╩ain澶栭潰鐨勶紝涓嶇劧蹇呯劧鍫嗘爤婧㈠嚭銆?br>2.鏄棰樹笉浠旂粏錛屽綋鎴愪簡澶氶噸杈撳叆錛屾悶浜嗕竴涓獁hile(scanf(...))錛岀粨鏋滆秴鏃朵簡銆傜涓嬈″湪UVA OJ涓婇潰瓚呮椂銆?br>
浣嗘槸榪欑瘒鏂囩珷閲嶇偣涓嶆槸璁茶繖涓紝鑰屾槸璁叉垜鍦ㄨ繍琛岃繃紼嬩腑緇忓父閬囧埌鐨刢ore dumped鐜拌薄銆傛垜鍦ㄧ綉涓婃壘鍒頒竴鐐硅祫鏂欙紝璐村湪涓嬮潰錛?br>
鍘熷笘錛?a >http://blogold.chinaunix.net/u3/98822/showart_2093542.html
浠涔堟槸Core Dump?
Core鐨勬剰鎬濇槸鍐呭瓨, Dump鐨勬剰鎬濇槸鎵斿嚭鏉? 鍫嗗嚭鏉?
寮鍙戝拰浣跨敤Unix紼嬪簭鏃? 鏈夋椂紼嬪簭鑾悕鍏跺鐨刣own浜? 鍗存病鏈変換浣曠殑鎻愮ず(鏈夋椂鍊欎細鎻愮ずcore dumped). 榪欐椂鍊欏彲浠ユ煡鐪嬩竴涓嬫湁娌℃湁褰㈠core.榪涚▼鍙風殑鏂囦歡鐢熸垚, 榪欎釜鏂囦歡渚挎槸鎿嶄綔緋葷粺鎶婄▼搴廳own鎺夋椂鐨勫唴瀛樺唴瀹規墧鍑烘潵鐢熸垚鐨? 瀹冨彲浠ュ仛涓鴻皟璇曠▼搴忕殑鍙傝?
core dump鍙堝彨鏍稿績杞偍, 褰撶▼搴忚繍琛岃繃紼嬩腑鍙戠敓寮傚父, 紼嬪簭寮傚父閫鍑烘椂, 鐢辨搷浣滅郴緇熸妸紼嬪簭褰撳墠鐨勫唴瀛樼姸鍐靛瓨鍌ㄥ湪涓涓猚ore鏂囦歡涓? 鍙玞ore dump.
濡備綍浣跨敤core鏂囦歡?
gdb -c core鏂囦歡璺緞 [搴旂敤紼嬪簭鐨勮礬寰刔
榪涘幓鍚庤緭鍏here鍥炶濺, 灝卞彲浠ユ樉紺虹▼搴忓湪鍝竴琛屽綋鎺夌殑, 鍦ㄥ摢涓嚱鏁頒腑.
涓轟粈涔堟病鏈塩ore鏂囦歡鐢熸垚鍛?
鏈夋椂鍊欑▼搴廳own浜? 浣嗘槸core鏂囦歡鍗存病鏈夌敓鎴? core鏂囦歡鐨勭敓鎴愯窡浣犲綋鍓嶇郴緇熺殑鐜璁劇疆鏈夊叧緋? 鍙互鐢ㄤ笅闈㈢殑璇彞璁劇疆涓涓? 鐒跺悗鍐嶈繍琛岀▼搴忎究鎴愮敓鎴恈ore鏂囦歡.
ulimit -c unlimited
銆?span style="TEXT-DECORATION: underline">娌℃湁鎵懼埌core鏂囦歡錛屾垜浠敼鏀箄limit鐨勮緗紝璁╁畠浜х敓銆?024鏄殢渚垮彇鐨勶紝瑕佹槸core鏂囦歡澶т簬1024涓潡錛屽氨浜х敓涓嶅嚭鏉ヤ簡銆傦級
$ ulimit -c 1024 錛堣漿鑰呮敞: 浣跨敤-c unlimited涓嶉檺鍒禼ore鏂囦歡澶у皬銆?br>
core鏂囦歡鐢熸垚鐨勪綅緗竴鑸簬榪愯紼嬪簭鐨勮礬寰勭浉鍚? 鏂囦歡鍚嶄竴鑸負core.榪涚▼鍙?br>
4. 鐢╣db鏌ョ湅core鏂囦歡:
涓嬮潰鎴戜滑鍙互鍦ㄥ彂鐢熻繍琛屾椂淇″彿寮曡搗鐨勯敊璇椂鍙戠敓core dump浜?
鍙戠敓core dump涔嬪悗, 鐢╣db榪涜鏌ョ湅core鏂囦歡鐨勫唴瀹? 浠ュ畾浣嶆枃浠朵腑寮曞彂core dump鐨勮.
gdb [exec file] [core file]
濡?
gdb ./test test.core
鍦ㄨ繘鍏db鍚? 鐢╞t鍛戒護鏌ョ湅backtrace浠ユ鏌ュ彂鐢熺▼搴忚繍琛屽埌鍝噷, 鏉ュ畾浣峜ore dump鐨勬枃浠?>琛?
===========================================================================
閫犳垚紼嬪簭core dump鐨勫師鍥犲緢澶氾紝榪欓噷鏍規嵁浠ュ線鐨勭粡楠屾葷粨涓涓嬶細
1 鍐呭瓨璁塊棶瓚婄晫
a) 鐢變簬浣跨敤閿欒鐨勪笅鏍囷紝瀵艱嚧鏁扮粍璁塊棶瓚婄晫
b) 鎼滅儲瀛楃涓叉椂錛屼緷闈犲瓧絎︿覆緇撴潫絎︽潵鍒ゆ柇瀛楃涓叉槸鍚︾粨鏉燂紝浣嗘槸瀛楃涓叉病鏈夋甯哥殑浣跨敤緇撴潫絎?/p>
c) 浣跨敤strcpy, strcat, sprintf, strcmp, strcasecmp絳夊瓧絎︿覆鎿嶄綔鍑芥暟錛屽皢鐩爣瀛楃涓茶/鍐欑垎銆傚簲璇ヤ嬌鐢╯trncpy, strlcpy, strncat, strlcat, snprintf, strncmp, strncasecmp絳夊嚱鏁伴槻姝㈣鍐欒秺鐣屻?/p>
2 澶氱嚎紼嬬▼搴忎嬌鐢ㄤ簡綰跨▼涓嶅畨鍏ㄧ殑鍑芥暟銆?/p>
搴旇浣跨敤涓嬮潰榪欎簺鍙噸鍏ョ殑鍑芥暟錛屽挨鍏舵敞鎰忕孩鑹叉爣紺哄嚭鏉ョ殑鍑芥暟錛屽畠浠緢瀹規槗琚敤閿欙細
asctime_r(3c) gethostbyname_r(3n) getservbyname_r(3n) ctermid_r(3s) gethostent_r(3n) getservbyport_r(3n) ctime_r(3c) getlogin_r(3c) getservent_r(3n) fgetgrent_r(3c) getnetbyaddr_r(3n) getspent_r(3c) fgetpwent_r(3c) getnetbyname_r(3n) getspnam_r(3c) fgetspent_r(3c) getnetent_r(3n) gmtime_r(3c) gamma_r(3m) getnetgrent_r(3n) lgamma_r(3m) getauclassent_r(3) getprotobyname_r(3n) localtime_r(3c) getauclassnam_r(3) etprotobynumber_r(3n) nis_sperror_r(3n) getauevent_r(3) getprotoent_r(3n) rand_r(3c) getauevnam_r(3) getpwent_r(3c) readdir_r(3c) getauevnum_r(3) getpwnam_r(3c) strtok_r(3c) getgrent_r(3c) getpwuid_r(3c) tmpnam_r(3s) getgrgid_r(3c) getrpcbyname_r(3n) ttyname_r(3c) getgrnam_r(3c) getrpcbynumber_r(3n) gethostbyaddr_r(3n) getrpcent_r(3n)
3 澶氱嚎紼嬭鍐欑殑鏁版嵁鏈姞閿佷繚鎶ゃ?/p>
瀵逛簬浼氳澶氫釜綰跨▼鍚屾椂璁塊棶鐨勫叏灞鏁版嵁錛屽簲璇ユ敞鎰忓姞閿佷繚鎶わ紝鍚﹀垯寰堝鏄撻犳垚core dump
4 闈炴硶鎸囬拡
a) 浣跨敤絀烘寚閽?/p>
b) 闅忔剰浣跨敤鎸囬拡杞崲銆備竴涓寚鍚戜竴孌靛唴瀛樼殑鎸囬拡錛岄櫎闈炵‘瀹氳繖孌靛唴瀛樺師鍏堝氨鍒嗛厤涓烘煇縐嶇粨鏋勬垨綾誨瀷錛屾垨鑰呰繖縐嶇粨鏋勬垨綾誨瀷鐨勬暟緇勶紝鍚﹀垯涓嶈灝嗗畠杞崲涓鴻繖縐嶇粨鏋勬垨綾誨瀷鐨勬寚閽堬紝鑰屽簲璇ュ皢榪欐鍐呭瓨鎷瘋礉鍒頒竴涓繖縐嶇粨鏋勬垨綾誨瀷涓紝鍐嶈闂繖涓粨鏋勬垨綾誨瀷銆傝繖鏄洜涓哄鏋滆繖孌靛唴瀛樼殑寮濮嬪湴鍧涓嶆槸鎸夌収榪欑緇撴瀯鎴栫被鍨嬪榻愮殑錛岄偅涔堣闂畠鏃跺氨寰堝鏄撳洜涓篵us error鑰宑ore dump.
5 鍫嗘爤婧㈠嚭
涓嶈浣跨敤澶х殑灞閮ㄥ彉閲忥紙鍥犱負灞閮ㄥ彉閲忛兘鍒嗛厤鍦ㄦ爤涓婏級錛岃繖鏍峰鏄撻犳垚鍫嗘爤婧㈠嚭錛岀牬鍧忕郴緇熺殑鏍堝拰鍫嗙粨鏋勶紝瀵艱嚧鍑虹幇鑾悕鍏跺鐨勯敊璇?
-------
鎴戣嚜宸辯▼搴廲ore dumped灝辨槸鍥犱負絎?涓師鍥狅紝鍫嗘爤婧㈠嚭銆傛垜鐨勫眬閮ㄦ暟緇勫紑鐨勮繃澶э紝鑰屽眬閮ㄥ彉閲忓垎閰嶅湪鏍堜笂錛屽鑷村爢鏍堟孩鍑恒?/p>
Links
As was mentioned in the section on file system structure, every file has a data structure (record) known as an i-node that stores information about the file, and the filename is simply used as a reference to that data structure. A link is simply a way to refer to the contents of a file. There are two types of links:
% cat a-file.txt
The file a-file.txt
%
Now we use the ln command to create a link to a-file.txt called b-file.txt:
% ls
./ ../ a-file.txt
% ln a-file.txt b-file.txt
% ls
./ ../ a-file.txt b-file.txt
The two names a-file.txt and b-file.txt now refer to the same data:
% cat b-file.txt
The file a-file.txt
%
If we modify the contents of file b-file.txt, then we also modify the contents of file a-file.txt:
% vi b-file.txt
...
% cat b-file.txt
The file a-file.txt has been modified.
% cat a-file.txt
The file a-file.txt has been modified.
%
and vice versa:
% vi a-file.txt
...
% cat a-file.txt
The file a-file.txt has been modified again!
% cat b-file.txt
The file a-file.txt has been modified again!
%
% ln -s a-file.txt b-file.txtOn disk, the file system would look like the following picture:
But what are the differences between the two types of links, in practice? Let us look at an example that highlights these differences. The directory currently looks like this (let us assume that a-file.txt b-file.txt are both hard links to the same file):
% ls
./ ../ a-file.txt b-file.txt
Let us first add another symbolic link using the -s option:
% ln -s a-file.txt Symbolicb-file.txt
% ls -F
./ ../ a-file.txt b-file.txt Symbolicb-file.txt@
A symbolic link, that ls -F displays with a @ symbol, has been added to the directory. Let us examine the contents of the file:
% cat Symbolicb-file.txt
The file a-file.txt has been modified again!
If we change the file Symbolicb-file.txt, then the file a-file.txt is also modified.
% vi Symbolicb-file.txt
...
% cat Symbolicb-file.txt
The file a-file.txt has been modified a third time!
% cat a-file.txt
The file a-file.txt has been modified a third time!
% cat b-file.txt
The file a-file.txt has been modified a third time!
%
If we remove the file a-file.txt, we can no longer access the data through the symbolic link Symbolicb-file.txt:
% ls -F
./ ../ a-file.txt b-file.txt Symbolicb-file.txt@
% rm a-file.txt
rm: remove `a-file.txt'? y
% ls -F
./ ../ b-file.txt Symbolicb-file.txt@
% cat Symbolicb-file.txt
cat: Symbolicb-file.txt: No such file or directory
The link Symbolicb-file.txt contains the name a-file.txt, and there no longer is a file with that name. On the other hand, b-file.txt has its own pointer to the contents of the file we called a-file.txt, and hence we can still use it to access the data.
% cat b-file.txt
The file a-file.txt has been modified a third time!
Although it may seem like symbolic links are not particularly useful, hard links have their drawbacks. The most significant drawback is that hard links cannot be created to link a file from one file system to another file on another file system. A Unix file structure hierarchy can consist of several different file systems (possibly on several physical disks). Each file system maintains its own information regarding the internal structure of the system and the individual files on the system. Hard links only know this system-specific information, which make hard links unable to span file systems. Soft links, on the other hand, know the name of the file, which is more general, and are able to span file systems.
For a concrete analogy, suppose that our friend Joel User is a student at both UBC and SFU. Both universities assign him a student number. If he tries to use his UBC student number at SFU, he will not meet with any success. He will also fail if he tries to use his SFU student number at UBC. But if he uses his legal name, Joel User, he will probably be successful. The student numbers are system-specific (like hard links), while his legal name spans both of the systems (like soft links).
Here is an example that demonstrates a situation where a hard link cannot be used and a symbolic link is needed. Suppose that we try to create a hard link from the current working directory to the C header stdio.h.
% ln /usr/include/stdio.h stdio.h
ln: creating hard link `stdio.h' to `/usr/include/stdio.h': Invalid cross-device link
%
The ln command fails because stdio.h is stored on a different file system. If we want to create a link to it, we will have to use a symbolic link:
% ln -s /usr/include/stdio.h stdio.h
% ls -l
lrwxrwxrwx 1 a1a1 guest 20 Apr 20 11:58 stdio.h -> /usr/include/stdio.h
% ls
./ ../ stdio.h@
%
Now we can view the file stdio.h just as if it was located in the working directory. For example:
% cat stdio.h
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
/* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T */
/* The copyright notice above does not evidence any */
/* actual or intended publication of such source code. */
/*
* User-visible pieces of the ANSI C standard I/O package.
*/
#ifndef _STDIO_H
#define _STDIO_H
...
%
The entire output of the cat command was not included to save space.
Note that the long listing (ls -l) of a soft link does not accurately reflect its associated permissions. To view the permissions of the file or directory that the symbolic link references, the -L options of the ls command can be used. For example:
% ln -s /usr/include/stdio.h stdio.h
% ls -l stdio.h
lrwxrwxrwx 1 a1a1 undergrad 20 May 10 15:13 stdio.h -> /usr/include/stdio.h
% ls -l /usr/include/stdio.h
-rw-r--r-- 1 root bin 11066 Jan 5 2000 /usr/include/stdio.h
% ls -lL stdio.h
-rw-r--r-- 1 root bin 11066 Jan 5 2000 stdio.h