What Is aLibrary?

Most people are familiar with

files (Dynamic Link Libraries) in Windows.

The Linux equivalent is a

file, a Shared Object, often referred to as just Library.

Tux mascot jumping from Windows to Linux.

A library can be used by an app allowing that program to utilize functionality from outside its program code.

It is a way of sharing common goods and interests in most, if not all, operating systems.

Thelddtool is another handy tool to have in any more advanced Linux user toolbox.

Terminal window showing the manual page for the Mutt email client on Linux

what isltrace?

Theltraceutility/tool traces all library calls.

Alike to

, we can start a programunder(think about it like a hierarchy)ltrace.

Article image

It does so by intercepting and recording thedynamiclibrary calls made by the program being executed.

libraries not directly compiled into a program;dynamiclibraries.

Next we created a directory~/workspaceand jumped into it.

Installing ltrace at the command line with apt

We then made three empty files using thetouchcommand, namely filesa,bandc.

This is not very useful this far.

Reasoning for a few seconds about howtarwill operate here will quickly reveal our next approach.

Our first ltrace run of tar

The avid reader may have also understood that thetarcommand internally would call thexzcommand.

The–xzoption passed to ourtarcommand line will ensure that thexzprogram is used for compression.

As such, we need to trace the child processes of the program running underltrace, i.e.tar.

ltrace of tar with follow (-f) to trace child processes

The reason is that we want to specify this option toltraceand not to thetarcommand.

All options after thetarcommand aretarspecific options whereas-fis an option specific toltrace.

The output is a bit more interesting.

Discovering more about the libraries used by tar and xz using the ldd command

Handy and all good.

So, where are our library calls?

Let’s have a look.

ltrace -S allows us to see system calls also

If you are interested in learning more about redirection seeBash Automation and Scripting Basics (Part 3).

Now that we added the-Soption, we can see all libraries being accessed.

For example, we see/etc/ld.so.preloadbeing accessed.

ltrace -t allows us to see timed output

in between, these will be shown inline at the moment they take place.

We installedltrace, set up a test environment, and executed someltracecommands with the most commonly used options.