8

Is there a way to view or get a list of executables that a program uses?

A particular example is file-roller. Is there a way to see which executables it uses, if there is more than one executable it could use for the same task, e.g. unrar and p7zip-rar.

The program 'ldd' can be used to view the libraries a programs uses, though not in real-time. Is there an equivalent for executables, preferably in real-time? Or some other method?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Eric
  • 81
  • 1
  • 2

2 Answers2

9

Try starting with strace. When one program calls another, it uses one of the exec system calls. For instance, given the following ruby script:

#!/usr/bin/env ruby
system("ls")
system("df")

I can grep strace output to find out what executables it runs:

$ strace -f ./test.rb  2>&1 | grep exec
execve("./test.rb", ["./test.rb"], [/* 23 vars */]) = 0
execve("/opt/opscode/embedded/bin/ruby", ["ruby", "./test.rb"], [/* 23 vars */]) = 0
[pid  7696] read(5, "ame+.  If the +exec_name+\n  # is"..., 8192) = 8192
[pid  7698] execve("/bin/ls", ["ls"], [/* 23 vars */] <unfinished ...>
[pid  7698] <... execve resumed> )      = 0
[pid  7700] execve("/bin/df", ["df"], [/* 23 vars */] <unfinished ...>
[pid  7700] <... execve resumed> )      = 0

The -f ensures that strace also traces child processes. At the beginning you can see the shell executing my script and the ruby interpreter. Then we can see that this script also executes /bin/ls and /bin/df. Note that this method will only show you the executables are used at run time, not all executables that might have been used if your runtime state had been different.

Steven D
  • 45,310
  • 13
  • 119
  • 114
  • 2
    Alternatively, `strace -e trace=process` makes `strace` only print out the process-related system calls, so the `grep` might then be unnecessary. (I think you can also use `strace -e trace=execve` to print out only calls to `execve()` exactly, and similarly for other system calls.) – David Z May 24 '14 at 23:42
-2

An easy method is to use top.

To determine whether file-roller is using either unrar or p7zip-rar, simply start top in a terminal, then extract a big rar file using file-roller.

While the rar file is being extracted, look at the terminal. If unrar is being used, the top process will be unrar; if p7zip-rar is being used, the top process will be 7z.

EmmaV
  • 3,985
  • 4
  • 30
  • 61
  • `top` will be very unwieldy, especially if the secondary processes don't top whatever sorting metric is being used. – muru Dec 28 '14 at 18:29
  • @muru: It works perfectly on my system. Archive extraction always uses the most CPU cycles (the default sorting metric), so the process responsible will always be at the top of the list. And even if it weren't at the top, how hard is it to look in the process list for either `unrar` or `7z`? – EmmaV Dec 28 '14 at 18:43
  • That's for one particular example. If I give you a random program, can you be certain this will work as well? And the whole point is to discover which programs are run. If I already know it runs 7z or unrar, what's the point? – muru Dec 28 '14 at 18:45
  • @muru: The point is to determine whether `file-roller` uses `p7zip-rar` or `unrar`, as in the asker's specific example. – EmmaV Dec 28 '14 at 18:49
  • Yes, it is a *specific example*, provided for the sake of an example. That doesn't mean the question is entirely about `file-roller`. – muru Dec 28 '14 at 18:50
  • @muru: Correct. And my answer will help those that want to determine which program is executed when there is more than one known possibility; the likely aim of the asker, given that he used it as an example. My answer is meant to supplement the others, not contradict them. – EmmaV Dec 28 '14 at 18:55
  • And I'm just noting that it's a poor answer, since it will not work well in general. – muru Dec 28 '14 at 18:56