Example of waitpid() in use?

Syntax of waitpid(): pid_t waitpid(pid_t pid, int *status, int options); The value of pid can be: < -1: Wait for any child process whose process group ID is equal to the absolute value of pid. -1: Wait for any child process. 0: Wait for any child process whose process group ID is equal to that … Read more

How is socket connection being handled in a forked process

First, accept() the incoming connection. The accepting process now has a handle to the listening socket, and the newly accepted socket. Fork and: In the child: Close the listening socket. Do stuff with the accepted socket. In the parent: Close the accepted socket. Resume the accept loop. The various socket resources will be reclaimed when … Read more

What does WEXITSTATUS(status) return?

WEXITSTATUS(stat_val) is a macro (so in fact it does not “return” something, but “evaluates” to something). For how it works you might like to look it up in the headers (which should be #included via <sys/wait.h>) that come with the C-compiler you use. The implementation of this macro might differ from one C-implementation to the … Read more

Why fork() works the way it does

This is due to historical reasons. As explained at https://www.bell-labs.com/usr/dmr/www/hist.html, very early Unix did have neither fork() nor exec*(), and the way the shell executed commands was: Do the necessary initialization (opening stdin/stdout). Read a command line. Open the command, load some bootstrap code and jump to it. The bootstrap code read the opened command, … Read more

What is the difference between using _exit() & exit() in a conventional Linux fork-exec?

You should use _exit (or its synonym _Exit) to abort the child program when the exec fails, because in this situation, the child process may interfere with the parent process’ external data (files) by calling its atexit handlers, calling its signal handlers, and/or flushing buffers. For the same reason, you should also use _exit in … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)