開発環境
- OS: macOS High Sierra - Apple
- Text Editor: Emacs
- コンパイラー: LLVM/Clang, GCC(gcc)
- プログラミング言語: C
Head First C ―頭とからだで覚えるCの基本 (David Griffiths (著)、Dawn Griffiths (著)、中田 秀基 (監修)、木下 哲也 (翻訳)、オライリージャパン)の9章(プロセスとシステムサービス - 限界を超える)、ごちゃごちゃのメッセージ(p. 412)を取り組んでみる。
ごちゃごちゃのメッセージ(p. 412)
Makefile
CC = cc all: sample 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() { /* donutsとcoffee */ /* char *my_env[] = {"FOOD=coffee", NULL}; */ /* if (execle("./coffee", "./coffee", "donuts", NULL, my_env) == -1) { */ /* fprintf(stderr, "プロセス0実行できません:%s\n", strerror(errno)); */ /* return 1; */ /* } */ /* creamとdonuts */ /* char *my_env[] = {"FOOD=donuts", NULL}; */ /* if (execle("./coffee", "./coffee", "cream", NULL, my_env) == -1) { */ /* fprintf(stderr, "プロセス0実行できません:%s\n", strerror(errno)); */ /* return 1; */ /* } */ /* coffeeとcoffee */ /* if (execl("./coffee", "coffee", NULL) == -1) { */ /* fprintf(stderr, "プロセス0実行できません:%s\n", strerror(errno)); */ /* return 1; */ /* } */ /* donutsとcoffee */ char *my_env[] = {"FOOD=coffee", NULL}; if (execle("./coffee", "./coffee", "donuts", NULL, my_env) == -1) { fprintf(stderr, "プロセス0実行できません:%s\n", strerror(errno)); return 1; } }
入出力結果(Terminal)
$ make cc sample.c -o sample ./sample donutsとcoffee $ make cc sample.c -o sample ./sample creamとdonuts $ make cc sample.c -o sample ./sample coffeeとcoffee $ make cc sample.c -o sample ./sample donutsとcoffee $
0 コメント:
コメントを投稿