On old SystemV Unix using the "truss" program(is similar to strace)
truss script.sh
.....
fork() = 382
6
Received signal #18, SIGCLD, in waitsys() [default]
siginfo: SIGCLD CLD_EXITED pid=382 uid=0 status=0x0000
.....
In the long output I can see the fork() syscall. I want to see the same thing(or similar) on Linux using strace.
I have tried
strace -e fork sh script.sh
and
strace -f sh script.sh
and
strace -f -e fork sh script.sh
But I cannot see the fork(). Linux and Old SystemV are of course different OS, and probably Unix use fork() in a different way from Linux, but the question is: how to see the fork() output using strace? Of course script.sh contain the same command "ls|wc -l" in both systems, I use it only for test.
Current versions of Linux provide a system call named
clone(2)
(see https://linux.die.net/man/2/clone and scroll down to the description ofsys_clone
), which is a general system call for creating new tasks. There are options to determine exactly what resources the new task should share with its parent (memory, file descriptors, etc), so that the system call can be used to create new processes or new threads or anything in between. Although the kernel still provides afork
system call for backward compatibility, current versions of glibc implementfork()
in terms ofclone(2)
instead.Thus, even though you may see a call to
fork()
in the source code ofsh
, the output ofstrace
will show aclone
system call. So you should look for that instead offork
.