You are on page 1of 14

Linux File System, Paths and

memory
Ing. Marco Andrés Ortiz N. MSc
Linux Filesystem Hierarchy Standard (FHS)
• Defines the directory structure and contents
• Maintained by the Linux Foundation
(https://www.youtube.com/watch?v=b55rd3fEYDE)
• Evolution of FHS
• Not used
• 1994: V1.0, V1.1 FSSTND (File System Standard)
• 1995: V1.2 FSSTND (File System Standard)
• 1997: V2.0 FHS
• 2000: v2.1 FHS
• 2001: v2.2 FHS
• https://refspecs.linuxfoundation.org/fhs.shtml
• Still Maintained FHS 2.3 released January 29, 2004.
• Latest version FHS 3.0 released June 3, 2015
Linux Filesystem Hierarchy Standard (FHS)

Required

[1]
Linux Filesystem Hierarchy Standard (FHS)

Required

[1]
Linux Filesystem Hierarchy Standard (FHS)

Optional

[1]
• Activity 1
• Go to the FHS Version 3.0 Standard document
• Compare: /bin vs /sbin commands
• In Linux:
• Identify these directories and their commands within
• See O.S version, Memory and CPU information from /proc
Paths
• Relative Paths: Relative to current working
directory
• ./ Represents current working directory.
• ../ Represents the parent directory.

• Absolute Paths
• specifying the location of a file or directory from the
root directory (/).

• Environment Path [2]


• Path with executable files from shell
• echo $PATH
• Activity 2:
• Copy and Move commands
• Create a directory that contains a simple C program export PATH=$PATH:/path/to/executable
and add this directory to as an environment path
Programs and processes
• Program: “executable file residing on disk in a directory. A program is read
into memory and is executed by the kernel as a result of one of the seven
exec functions.” [3]

• A program being executed is called process or task. Every generated


process has a unique identifier called Process ID (PID) [3]

Later in ALSE:
• Activity 3: Process Control:
fork, exec, and waitpid
• Identify Linux PIDs with top and ps commands
• Generate a custom process and see its PID
Process Environment
• A C program starts execution when main function called Activity 4: main
arguments example

• “When a C program is executed by the kernel (exec) a special start-up


routine is called before the main function is called.” [3]

• Process termination [3]


• Normal termination: Return from main, Calling exit, Calling _exit or _Exit,
Return of the last thread from its start routine, Calling pthread_exit from the
last thread
• Abnormal termination: Calling abort, Receipt of a signal, Response of the last
thread to a cancellation request
Memory of a C Program
Process Address
Space
Process N

Process 2

Process 1

System libraries

Kernel

Hardware (CPU, RAM, I/O)


[3]
Memory of a C Program
• Text segment, consisting of the machine instructions that the CPU executes. is
often read-only, to prevent a program from accidentally modifying its
instructions.
• Initialized data segment, usually called simply the data segment, containing
variables that are specifically initialized in the program (“Global variables” or
static)
• Uninitialized data segment, called the ‘‘bss’’ Data in this segment is initialized by
the kernel to arithmetic 0 or null pointers before the program starts executing.
(“Global variables” or static)
• where automatic variables (“local variables”) are stored, along with information
that is saved each time a function is called.
• Heap, where dynamic memory allocation usually takes place.
• malloc() , free() in C
• new(), delete () in C++ [3]
Memory of a C Program
• C models of memory management:

• Automatic variables: Without the static keyword, any variable inside a function is
automatic. (Local to function)

• Static variables: Exist in the same place throughout the life of the program. Variables
declared outside of functions (in file scope) and inside functions with the static
keyword. Array sizes are fixed at startup, but values can change. Initialized to all zeros
(or NULL) when no other initialization. any initializations must be done with
constants that require no calculations.

• Manual variables: malloc and free. The only type of memory where arrays can be
resized after declaration.

Ben Klemens - 21st Century C_ C Tips from the New School-O'Reilly Media (2014)
Memory of a C Program

Ben Klemens - 21st Century C_ C Tips from the New School-O'Reilly Media (2014)
Memory of a C Program
• Activity 5:
• With a basic C program example, use the following commands to identify
memory behavior:
• size --format=Berkeley
• size --format=SysV
• objdump –s
References
• [1] LSB Workgroup, The Linux Foundation. Filesystem Hierarchy Standard.
Version 3.0. March 19, 2015
• [2] https://www.geeksforgeeks.org/absolute-relative-pathnames-unix/
accesed: 9/19/2021
• [3] Stevens, W. Rago S. Advanced Programming in the UNIX® Environment
Third Edition. Addison-Wesley. 2013
• [4] Ben Klemens - 21st Century C_ C Tips from the New School-O'Reilly
Media (2014)
• Other sites:
• https://www.youtube.com/watch?v=_8-ht2AKyH4
• https://www.geeksforgeeks.org/memory-layout-of-c-program/

You might also like