I compiled the code with rustc main.rs and then tried to trace the clone() syscall using the command: strace -f -e clone,fork,execve,futex ./main.elf
However, to my surprise, there was no clone() syscall as shown in the output below:
strace: Process 686239 attached
hi number 1 from the main thread!
hi number 1 from the spawned thread!
hi number 2 from the main thread!
hi number 2 from the spawned thread!
hi number 3 from the main thread!
hi number 3 from the spawned thread!
hi number 4 from the main thread!
hi number 4 from the spawned thread!
[pid 686239] +++ exited with 0 +++
+++ exited with 0 +++
I ran it multiple times, but never observed clone() syscall in the strace output. Shouldn't thread::spawn in that code lead to clone() syscall on my Ubuntu 24.04 system? System details below:
bash$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 24.04.2 LTS
Release: 24.04
Codename: noble
bash$ uname -r
6.11.0-25-generic
bash$ uname -m
x86_64
The clone syscall has different variants over the years, and even differences between architectures. On my Fedora 42 x86_64, I get clone3 for the thread.
BTW, strace also has a -e process group that captures all of these.
I was gonna ask a follow-up question if there was any strace syscall group I could use like -e memory. @cuviper 's asnwer above: Thread::spawn does not lead to clone() syscall? - #2 by cuviper provides that info as well: -e process. This provides a more generic way to track clone*() syscalls.