unix環境高階程式設計之環境搭建

2021-09-14 05:18:25 字數 1741 閱讀 1762

首先,apue.h不是系統自有的,而是做著自己的寫的,因此,本書程式設計的第一步就是將該檔案包含下來:

2.執行一下 ls, 發現多了乙個apue.3e,cd 命令進入該目錄

3.執行 make

***第三步一般都會出錯,提示是需要 bsd, 執行 apt(yum) install -y libbsd-dev,重新執行make 即可

4.將編譯後的相應標頭檔案放入系統中,因為程式編譯時所需的標頭檔案是從系統路徑下獲取的,具體分為兩步:

cp ./include/apue.h /usr/include/

cp ./lib/libapue.a /usr/local/lib/

5.錯誤處理函式,err_sys(),之類的函式也是作者自己寫的,所以需要重新修改

在 /usr/include 下新建乙個my_err.h,內容為:

#include /* for definition of errno */

#include /* iso c variable aruments */

static void err_doit(int, int, const char *, va_list);

/* * nonfatal error related to a system call.

* print a message and return.

*/void

err_ret(const char *fmt, ...)

/* * fatal error related to a system call.

* print a message and terminate.

*/void

err_sys(const char *fmt, ...)

/* * fatal error unrelated to a system call.

* error code passed as explict parameter.

* print a message and terminate.

*/void

err_exit(int error, const char *fmt, ...)

/* * fatal error related to a system call.

* print a message, dump core, and terminate.

*/void

err_dump(const char *fmt, ...)

/* * nonfatal error unrelated to a system call.

* print a message and return.

*/void

err_msg(const char *fmt, ...)

/* * fatal error unrelated to a system call.

* print a message and terminate.

*/void

err_quit(const char *fmt, ...)

/* * print a message and return to caller.

* caller specifies "errnoflag".

*/static void

err_doit(int errnoflag, int error, const char *fmt, va_list ap)

在之後的程式中,只需將my_err.h包入即可。

UNIX環境高階程式設計之syslog

核心程式可以呼叫log函式記日誌.任何使用者程序可以開啟並讀取 dev klog裝置讀取這些訊息 大多數使用者程序,呼叫syslog函式產生日誌訊息.這使得訊息傳送到unix域資料報套接字 dev log 使用者程序傳送日誌訊息到udp埠514 通常syslogd守護程序會讀取乙個配置檔案 etc ...

unix環境高階程式設計之程序

每個程序都有乙個非負整型表示的唯一程序id。但是程序id是可重用的。id為0的程序通常是排程程序,也叫叫喚程序,該程序是核心的一部分。程序1通常是init程序,在自舉過程結束時由核心呼叫 sbin init中 附註 oo c程式的儲存空間布局 1 正文段 2 初始化資料段 3 非初始化資料段 4 棧...

unix環境高階程式設計

unix 日曆時間 自1970 年1 月1 日00 00 00 以來的國際標準時間 utc 程序時間 cpu 時間 時鐘時間 程序執行時間的總量。使用者cpu 時間 執行使用者指令時間量。系統cpu 時間 執行核心所經歷時間。命令 time 第三章至第七章 原子操作 任何乙個要求多於1 個函式呼叫的...