2007-08-01から1ヶ月間の記事一覧
スティッキービット(S_ISVTXビット)は本来、プログラムの実行速度を向上させることを目的として使用されていた。実行可能プログラムでこのビットがオンであると、最初にプログラムを実行した時、プロセスが終了してもプログラムのテキスト領域はスワップファ…
lstat()とPOSIXマクロを使用して、コマンド行の各引数のファイルの種類を出力するプログラム。lstat()を使用しないと、シンボリックリンクを検出できない。 #include #include #include "ourhdr.h" int main(int argc, char *argv[]) { char *ptr; int i; in…
実行中のプロセスのcoreダンプを取得するスクリプト。メイン処理は↓ ulimit -cがゼロでも出力されるみたい。 /usr/bin/gdb > /dev/null gcore $name.$pid detach quit EOF
dup2()はファイルディスクリプタを複製する。 #include #include "ourhdr.h" int main(int argc, char *argv[]) { int fd; /* 引数のチェック */ if (argc != 2) { err_quit("a single argument (the file name) is required"); } /* ファイルをオープンして…
fcntl()は、オープンしているファイルの属性を変更することが出来る。以下は指定したディスクリプタのファイル状態フラグを出力するプログラム。 #include #include #include "ourhdr.h" int main(int argc, char *argv[]) { int accmode; int val; int n; i…
#include #include "ourhdr.h" int main(void) { off_t res; /* 現在の位置から0バイトシークすることにより、カレントオフセットを取得する。 * lseek()はパイプやFIFOを参照するファイルディスクリプタに対しては-1を返し * てerrnoを設定する。 */ res = …
標準Cにはエラー処理関数としてstrerror()とperror()が用意されている。 #include #include #include #include int main(int argc, char *argv[]) { char *msg; msg = strerror(EACCES); fprintf(stderr, "ENOENT: %s\n", msg); errno = EACCES; perror(argv…
sbrk()はメモリ割付を処理する。sbrk()はプロセスのデータ空間を指定したバイトだけ増やす。新たなメモリ空間をどのように管理するかは、プロセスの責任である。malloc()は1つの割付方式を実現する。malloc()を使用せず、sbrkを用いた独自のメモリ割付アルゴ…
シェルの骨格となるプログラム。 #include #include #include "ourhdr.h" int main(void) { char buf[MAXLINE]; pid_t pid; int status; printf("%% "); /* 標準入力から一度に1行読み込む。ファイルの終了文字(Control-D)をタイプする * とfgetsはNULLポイ…
#include "ourhdr.h" #define BUFFSIZE 8192 int main(void) { int n; char buf[BUFFSIZE]; while ( (n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0) { if (write(STDOUT_FILENO, buf, n) != n) { err_sys("write error"); } } if (n
#include #include #include "ourhdr.h" int main(int argc, char *argv[]) { DIR *dp; struct dirent *dirp; if (argc != 2) { err_quit("a single argument (the directory name) is required"); } /* ディレクトリストリームをオープンする */ if ( (dp =…
プログラム ディスクファイルに収められた実行可能ファイルのこと。6つあるexec()のうちの1つを呼出すとカーネルはプログラムをメモリへ読み込む。 プロセス プログラム実行中のインスタンスをプロセスと呼ぶ。
set history save on set history size 10000 set history filename ~/.gdb_history set print pretty on set print static-members off set charset ASCII
以下が使用例。system()の返り値はwait()で定義されているフォーマットで帰ってくるので、wait.hで定義されているマクロを使用して検査するのがポイント。 #include #include int main(void) { int i; int stat[3]; int stat2[3]; char *command[] = { "ping…