信號章節相關概念

core文件的簡單介紹

//---------------------------------------------------------------

1. core文件的簡單介紹
//---------------------------------------------------------------

在一個程序崩潰時,它一般會在指定目錄下生成一個core文件。core文件僅僅是一個內存映象(同時加上調試信息),主要是用來調試的。


//---------------------------------------------------------------
2. 開啓或關閉core文件的生成
//---------------------------------------------------------------

用以下命令來阻止系統生成core文件:
ulimit -c 0
下面的命令可以檢查生成core文件的選項是否打開:
ulimit -a
該命令將顯示所有的用戶定製,其中選項-a代表“all”。

也可以修改系統文件來調整core選項
在/etc/profile通常會有這樣一句話來禁止產生core文件,通常這種設置是合理的:
# No core files by default
ulimit -S -c 0 > /dev/null 2>&1
但是在開發過程中有時爲了調試問題,還是需要在特定的用戶環境下打開core文件產生的設置
在用戶的~/.bash_profile里加上ulimit -c unlimited來讓特定的用戶可以產生core文件
如果ulimit -c 0 則也是禁止產生core文件,而ulimit -c 1024則限制產生的core文件的大小不能超過1024kb


//---------------------------------------------------------------
3. 設置Core Dump的核心轉儲文件目錄和命名規則
//---------------------------------------------------------------

/proc/sys/kernel/core_uses_pid可以控制產生的core文件的文件名中是否添加pid作爲擴展,如果添加則文件內容爲1,否則爲0
proc/sys/kernel/core_pattern可以設置格式化的core文件保存位置或文件名,比如原來文件內容是core-%e
可以這樣修改:
echo "/corefile/core-%e-%p-%t" > core_pattern
將會控制所產生的core文件會存放到/corefile目錄下,產生的文件名爲core-命令名-pid-時間戳
以下是參數列表:
    %p - insert pid into filename 添加pid
    %u - insert current uid into filename 添加當前uid
    %g - insert current gid into filename 添加當前gid
    %s - insert signal that caused the coredump into the filename 添加導致產生core的信號
    %t - insert UNIX time that the coredump occurred into filename 添加core文件生成時的unix時間
    %h - insert hostname where the coredump happened into filename 添加主機名
    %e - insert coredumping executable name into filename 添加命令名


//---------------------------------------------------------------
4. 使用core文件
//---------------------------------------------------------------

在core文件所在目錄下鍵入:
gdb -c core
它會啓動GNU的調試器,來調試core文件,並且會顯示生成此core文件的程序名,中止此程序的信號等等
如果你已經知道是由什麼程序生成此core文件的,比如MyServer崩潰了生成core.12345,那麼用此指令調試:
gdb -c core MyServer
以下怎麼辦就該去學習gdb的使用了


//---------------------------------------------------------------
5. 一個小方法來測試產生core文件
//---------------------------------------------------------------

直接輸入指令:
kill -s SIGSEGV $$

2.軟件中斷與硬件中斷的區

硬件中斷時通過中斷請求線輸入信號來請求處理機;軟件中斷是處理機內部識別並進行處理的中斷過程。硬件中斷一般是由中斷控制器提供中斷碼類型,處理機自動轉向中斷處理程序;軟件中斷完全有處理機內部形成中斷處理程序的入口地址並轉向中斷處理程序的入口地址,並轉向中斷處理程序,不需要外部提供信息。
3.異步事件和同步事件的區別

In synchronous receiving, while the server is waiting to receive data from a client, if the stream is empty the main thread will block until the request for data is satisfied. Hence, the server cannot do anything else until it receives data from the client. If another client attempts to connect to the server at that time, the server cannot process that request because it is blocked on the first client. This behavior is not acceptable for a real-world application where we need to support multiple clients at the same time.

In asynchronous communication, while the server is listening or receiving data from a client, it can still process connection requests from other clients as well as receive data from those clients. When a server is receiving asynchronously, a separate thread (at the OS level) listens on the socket and will invoke a callback function (specified when the asynchronous listening was commenced) when a socket event occurs. This callback function in turn will respond and process that socket event. For example, if the remote program writes some data to the socket, a "read data event" (callback function you specify) is invoked; it knows how to read the data from the socket at that point.

簡而言之,同步是一對一的,異步是一對多的。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章