Skip to content
Advertisement

Interpreting STRACE output – pipes and forks

I have the following code written in C, taken from https://beej.us/guide/bgipc/html/multi/pipes.html:

JavaScript

When compiling and running this code in the terminal using strace I get the following output:

JavaScript

Can anybody explain, line by line, what is going on in the strace output? I’ve attempted to research how to interpret strace outputs but haven’t had any luck.

Thanks in advance.

Advertisement

Answer

JavaScript

The shell calls execve with your executable and ./forks as argv[0]. The /* 55 vars */ are the environment variables inherited from the shell.

JavaScript

Probably sets up thread local storage for the newly launched process.

JavaScript

The pipe system call returns a pair of descriptors, 3 and 4. The numbers are such because no descriptors other than 0 (stdin), 1 (stdout) and 2 (stderr) have been allocated so far to the process.

JavaScript

The clone system call corresponds to the call to fork, spawning a new process. Even though fork is commonly referred to as a system call, particularly on Linux it wraps a call to clone(2).

JavaScript

Within the parent and the child, two new executables are started. The child exits with [pid 7304] exit_group(0) and the parent immediately receives a SIGCHLD signal that a child process has changed its state.

Advertisement