Thread::spawn does not lead to clone() syscall?

I was readng through Using Threads to Run Code Simultaneously - The Rust Programming Language and tried the sample code there.

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.

2 Likes

clone is the old interface.
clone3 is what's actually used:

$ strace -f -e clone3 ./thread >/dev/null
clone3({flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, child_tid=0x7f2e5a63f990, parent_tid=0x7f2e5a63f990, exit_signal=0, stack=0x7f2e5a43f000, stack_size=0x1fff00, tls=0x7f2e5a63f6c0}strace: Process 32656 attached
 => {parent_tid=[32656]}, 88) = 32656
[pid 32656] +++ exited with 0 +++
+++ exited with 0 +++
1 Like

Thankyou! -e process is pretty convenient. Thanks for that as well!

Oh ok, makes sense now! Thankyou!

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.

There's a list on this page and memory is listed: https://strace.io/

Oh, there's also a list in the man page. Search for %memory.

1 Like