#include #include #include #include int main() { pid_t pid = fork(); if (pid < 0) { perror("fork"); exit(-1); } else if (pid == 0) { // 子プロセスで別プログラムを実行 execl("./Client/test", "./Client/test", "-u", "HOGE", NULL); exit(-1); } // 親プロセス int status; //子プロセスの終了待ち pid_t r = waitpid(pid, &status, 0); if (r < 0) { perror("waitpid"); exit(-1); } if (WIFEXITED(status)) { // 子プロセスが正常終了の場合 printf("child exit-code=%d\n", WEXITSTATUS(status)); } else { printf("child status=%04x\n", status); } return 0; }