Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell how many threads a Linux binary is creating without source?

Suppose I have a generic binary without source and I want to determine whether it is running serially or spawns multiple threads.

Is there a way I can do this from the linux command line?

like image 654
merlin2011 Avatar asked May 16 '13 20:05

merlin2011


1 Answers

First install strace.

$ yum install strace

Run the program with strace, and look for clone or fork system calls. Here's a quick example with a program I wrote that just calls fork and returns.

$ strace ./a.out 

execve("./a.out", ["./a.out"], [/* 43 vars */]) = 0
brk(0)                                  = 0x74f000
...
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fb22b16da10) = 6567
exit_group(1)                           = ?
+++ exited with 1 +++
like image 190
Jonathon Reinhart Avatar answered Nov 03 '22 00:11

Jonathon Reinhart