Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

COMPUTER

ORGANIZATION
OVERVIEW
● Deadlocks handling in Windows and Linux
● Library hierarchy
● Static vs Dynamic Linking
● Dynamic loading and linking
DEADLOCKS
● A deadlock occurs when two or more tasks permanently block each other by each task having a lock on a resource
which the other tasks are trying to lock.
● Deadlocks occur if following 4 conditions hold simultaneously:
○ Mutual Exclusion
○ Hold and Wait
○ No preemption
○ Circular wait
/lib – Essential Shared Libraries

The lib folder is a library files directory which contains all

helpful library files used by the system. In simple terms,

these are helpful files which are used by an application or a

command or a process for their proper execution.


/lib/'machine-architecture'

/lib/iptables

/lib/kbd
OTHER LIBRARY FOLDERS IN LINUX
/lib/modules/'kernel-version'

/usr/lib – All software libraries are installed here.


/lib/modules/'kernel-version'/isapnpmap.dep
This does not contain system default or kernel
/lib/modules/'kernel-version'/modules.dep
libraries.

/usr/local/lib – To place extra system library files /lib/modules/'kernel-version'/pcimap

here. These library files can be used by different /lib/modules/'kernel-version'/usbmap


applications.
/lib/oss
/var/lib – Holds dynamic data libraries/files like
/lib/security
the rpm/dpkg database and game scores.
Static Vs Dynamic Linking
Creating libraries in Linux

Creating a dynamic library in Linux Creating a static library in Linux

1. Creating object files: gcc *.c -c -fpic 1. Creating object files: gcc *.c -c -fpic
2. Compiling object files into dynamic 2. Archive the library: ar rcs liball.a *.0
library: gcc *0 -shared -o liball.so 3. Including a prototype for each of the
3. Adding the location for the library file: function that exist in the created library
export LD_LIBRARY_PATH=$PWD:
$LD_LIBRARY_PATH
Dynamic loading and linking within Linux

LINKING:
In Unix-like systems that use ELF for executable images and dynamic libraries, such as Solaris, 64-bit versions of
HP-UX, Linux, FreeBSD, NetBSD, OpenBSD, and DragonFly BSD, the path of the dynamic linker that should be
used is embedded at link time into the .interp section of the executable's PT_INTERP segment. In those systems,
dynamically loaded shared libraries can be identified by the filename suffix .so (shared object).
LOADING:
Loading the library is accomplished with dlopen on UNIX-like operating systems. Examples follow:

Most UNIX-like operating systems (Solaris, Linux, *BSD, etc.)


void* sdl_library = dlopen("libSDL.so", RTLD_LAZY);
if (sdl_library == NULL) {
// report error ...
} else {
// use the result in a call to dlsym
}

Function Description

dlopen Makes an object file accessible to a program

dlsym Obtains the address of a symbol within a dlopen ed object file

dlerror Returns a string error of the last error that occurred

dlclose Closes an object file

You might also like