c - Why is waitpid not waiting for a process to quit? -
i have simple code written in c , os osx: int main() { pid_t pid = 1244; int pid_status; waitpid(pid, &pid_status, 0); printf("%i\n",pid_status); } 1244 process id opera browser running right now: korays-macbook-pro:helloworld koraytugay$ ps -p 1244 pid tty time cmd 1244 ?? 0:09.19 /applications/opera.app/contents/macos/opera what expect happen when run program, should wait until close opera, is: korays-macbook-pro:helloworld koraytugay$ ./koko 1798668342 korays-macbook-pro:helloworld koraytugay$ ./koko 1637806134 korays-macbook-pro:helloworld koraytugay$ ./koko 1707163702 why program directly quitting , these different numbers? waitpid effective child processes. see manual page http://man7.org/linux/man-pages/man2/wait.2.html . you find waitpid returning -1. please check errno