• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

ltrace Command Examples in Linux

by Deepika

The ltrace command can be used to intercept and record the dynamic calls made to shared libraries. The amount of output generated by the ltrace command can be overwhelming for some commands (especially if the -S option is used to also show system calls). You can focus the output to just the interaction between the program and some list of libraries. For example, to execute the id -Z command and show the calls made to the libselinux.so module, execute:

$ ltrace -l /lib/libselinux.so.1 id -Z
is_selinux_enabled(0xc1c7a0, 0x9f291e8, 0xc1affc, 0, -1)a
       =1	
getcon(0x804c2c8, 0xfee80ff4, 0x804b179, 0x804c020, 0)a
       =0
user_u:system_r:unconfined_t

Remember that you can see what libraries a program is linked against using the ldd command.

ltrace Command Examples

1. Print (trace) library calls of a program binary:

# ltrace ./program

2. Count library calls. Print a handy summary at the bottom:

# ltrace -c path/to/program

3. Trace calls to malloc and free, omit those done by libc:

# ltrace -e malloc+free-@libc.so* path/to/program

4. Write to file instead of terminal:

# ltrace -o file path/to/program

Filed Under: Linux

Some more articles you might also be interested in …

  1. Understanding the Network interface configuration file /etc/sysconfig/network-scripts/ifcfg-eth#
  2. GoBuster: command not found
  3. exec: command not found
  4. conntrack: command not found
  5. fsck: command not found
  6. How to gzip all or specific files in Linux
  7. Change default kernel (boot with old kernel) in CentOS/RHEL/OEL 5 and 6
  8. ifrename: command not found
  9. i3: command not found
  10. halt: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright