開発環境
- OS: macOS High Sierra - Apple
- Text Editor: Emacs
- コンパイラー: LLVM/Clang, GCC(gcc)
- プログラミング言語: C
Head First C ―頭とからだで覚えるCの基本 (David Griffiths (著)、Dawn Griffiths (著)、中田 秀基 (監修)、木下 哲也 (翻訳)、オライリージャパン)の9章(プロセスとシステムサービス - 限界を超える)、エクササイズ(p. 409)を取り組んでみる。
エクササイズ(p. 409)
Makefile
CC = cc all: run sample: sample.c $(CC) sample.c -o sample run: sample ./sample
#include <errno.h> #include <stdio.h> #include <string.h> #include <unistd.h> int main() { if (execl("/sbin/ifconfig", "/sbin/ifconfig", NULL) == -1) { if (execlp("ipconfig", "ipconfig", NULL) == -1) { fprintf(stderr, "ipconfigを実行できません: %s\n", strerror(errno)); return 1; } } }
入出力結果(Terminal)
$ make cc sample.c -o sample ./sample ... $ echo $? 0 $
0 コメント:
コメントを投稿