Time of Update: 2018-12-03
所有的unix,包括linux,以1970年1月1日午夜(0點)為起點。linux系統中所有的時間都以從那時起經過的秒數來衡量。時間類型:time_t#include <time.h>time_t time(time_t *tloc); struct tm* gmtime(const time_t *timeval);代碼:time_t tim=time(NULL);struct tm * tm_ptr=gmtime(&tim);printf("week:
Time of Update: 2018-12-03
臨時檔案的使用需要注意:檔案不可同時被多個任務編輯char *tmpnam(char *s) 建立與當前已存在的所有檔案不同名的檔案問題:其他程式也能open and edit與tmpnam返回的檔案名稱同名的檔案註:檔案名稱is assumed to至少L_tmpnam(通常是20)characters long該函數至多能被調用TMP_MAX(至少幾千)次in a single program. FILE *tmpfile(void);
Time of Update: 2018-12-03
除了init程式外,所有的linux程式都是由其他程式或使用者啟動的UID是使用者身份的關鍵,類型uid_t#include <sys/types.h>#include <unistd.h>uid_t getuid(void); 啟動程式的使用者的UIDchar* getlogin(void); 與目前使用者關聯的登陸名 /etc/passwd/etc/shadow #include <sys/types.h>#include
Time of Update: 2018-12-03
以下內容摘自 beginning linux programming 一書編譯時間加上 -lncurses選項#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <curses.h>int main(){int i;initscr();if(!has_colors()){endwin();fprintf(stderr,"error - no color support
Time of Update: 2018-12-03
在基於ARM的嵌入式系統開發中,常常用到交叉編譯的GCC工具鏈有兩種:arm-linux-*和 arm-elf-*,兩者區別主要在於使用不同的C庫檔案。arm-linux-*使用GNU的Glibc,而arm-elf-*一般使用 uClibc/uC-libc或者使用REDHAT專門為嵌入式系統的開發的C庫newlib.Glibc。uClibc/uC-libc以及 newlib都是C語言庫檔案,只是所應用的領域不同而已,Glibc是針對PC開發的,uClibc/uC-libc是與Glibc
Time of Update: 2018-12-03
《精通unix下c語言-編程與項目實踐》學習筆記1.庫的分類 庫可分為靜態庫和動態庫兩種。
Time of Update: 2018-12-03
linux壓縮和解壓縮命令大全 .tar 解包:tar zxvf FileName.tar 打包:tar czvf FileName.tar DirName --------------------------------------------- .gz 解壓1:gunzip FileName.gz 解壓2:gzip -d FileName.gz 壓縮:gzip FileName .tar.gz 和 .tgz 解壓:tar zxvf
Time of Update: 2018-12-03
隨著Linux應用的擴充許多朋友開始接觸Linux,根據學習Windows的經驗往往有一些茫然的感覺:不知從何處開始學起。這裡介紹學習Linux的一些建議。 一、從基礎開始:常常有些朋友在Linux論壇問一些問題,不過,其中大多數的問題都是很基礎的。例如:為什麼我使用一個命令的時候,系統告訴我找不到該目錄,我要如何限制使用者的許可權等問題,這些問題其實都不是很難的,只要瞭解了 Linux 的基礎之後,應該就可以很輕易的解決掉這方面的問題。而有些朋友們常常一接觸Linux
Time of Update: 2018-12-03
以下內容來自 beginning linux programming一書第5章 終端#include <stdio.h>#include <stdlib.h>#include <termios.h>char *menu[] = {"a - add new record","d - delete record","q - quit",NULL,};int getchoice(char *greet,char *choices[],FILE *in,
Time of Update: 2018-12-03
以下內容轉自http://hi.baidu.com/tekuba/item/b247ce5a9a8653c8d2e10c51 errno - number of last errorerrno 記錄linux系統的最後一次錯誤碼。代碼是一個int型的值,在errno.h中定義 注意引用他的方法,看下面一例:if (somecall() == -1){ printf("somecall() failed\n");if(errno == ...){ ...
Time of Update: 2018-12-03
fileno函數:檔案流(FILE*)->檔案描述符#include <stdio.h>int main(void){ FILE * fp; //檔案流int fd; //檔案描述符fp=fopen("/home/yaoyin/bin/test/1.c","r");fd=fileno(fp); printf("fd=%d\n",fd);fclose(fp);return 0;}結果: fd=3(0 stdin 1 stdout 2 stderr
Time of Update: 2018-12-03
以下內容摘自 beginning linux programming#include <termios.h>#include <stdio.h>#include <stdlib.h>#define PASSWORD_LEN 8int main(){struct termios its,newits;char password[PASSWORD_LEN+1];tcgetattr(fileno(stdin),&its);newits =
Time of Update: 2018-12-03
F_GETLK, F_SETLK and F_SETLKW are used to acquire, release, and test for the existence of record locks (also known as file-segment or file- region locks). The third argument, lock, is a pointer to a structure that has at
Time of Update: 2018-12-03
#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <fcntl.h>#include <errno.h>int main(){int file_desc;int save_errno;file_desc = open("/tmp/LCK.test",O_RDWR|O_CREAT|O_EXCL,0444);if(file_desc ==
Time of Update: 2018-12-03
以下內容來自 beginning linux programming/dev/tty 指向當前終端或當前的登陸會話,可將它當作檔案一樣操作代碼:menu1.c#include <stdio.h>#include <stdlib.h>char *menu[] = {"a - add new record","d - delete record","q - quit",NULL,};int getchoice(char *greet,char
Time of Update: 2018-12-03
以下代碼摘自linux程式設計 英文名:beginning linux programming#include <stdio.h>#include <stdlib.h>char *menu[] = {"a - add new record","d - delete record","q - quit",NULL,};int getchoice(char *greet,char *choices[]);int main(){int choice =
Time of Update: 2018-12-03
以下內容來自 linux beginning programming #include <unistd.h>#include <stdlib.h>#include <curses.h>int main(){WINDOW *new_window_ptr;WINDOW *popup_window_ptr;int x_loop;int y_loop;char a_letter =
Time of Update: 2018-12-03
移動:方向鍵上、下:移動一行空格:向後一屏b(小寫):向前一屏先輸入數字,比如3,然後按上述的鍵,可相應上下移動3行,翻滾3屏。u 向前半屏d 向後半屏 搜尋:/abc 搜尋含有abc的字串在搜尋到結果後,按n鍵向後繼續搜尋,N鍵則是向前。 跳轉:g 跳到整篇文章的起始G 跳到整篇文章的末尾p 先輸入50,再按p,跳到文章的一半位置處(p是percent百分比的縮寫) 編輯命令行:HOME 移動游標到行首END 移動游標到行尾control+U刪除整行
Time of Update: 2018-12-03
以下內容轉自http://blog.163.com/lghct@126/blog/static/64551808201024101630455/ curses庫是用來開發簡單圖形介面程式一個庫(也許它的功能不止這些,但是目前我只知道這一個!:)。Ubuntu下安裝方法:sudo apt-get install libncurses5-devcurses的基本用法如下:1. 包含標頭檔:curses.h2. 編譯時間應加上連結語句-lcurses,如:gcc temp.c -o temp
Time of Update: 2018-12-03
代碼: 1.c#include <unistd.h>#include <stdio.h>#include <stdlib.h>int main(){ if(!isatty(fileno(stdout))){fprintf(stderr,"You are not a terminal\n");exit(1);}exit(0);}gcc 1.c -o t./t ./t > file 輸出You are not a