Category Archives: Operating system

An operating system is a set of programs that put the computer hardware available to users in a secure way

Operating system

Operating system

An operating system is a set of programs that, by providing abstractions, they put the hardware of the machine available to users in a safe and effective

Objectives of an operating system:

  • To simplify the use of the machine
  • To make efficient use of the resources of the machine
  • Control the execution of application programs

Functions of the operating system

The operating system as user interface:

  • Interpreter command or shell (text or graphics)
  • Files commands or shell scripts

The operating system as resources manager (Resolves competition for resources):

  • Allocation and recovery of resources
  • Protection between users
  • Accounting and monitoring

The operating system as a virtual machine. Offers services to the user processes via a set of functions (system calls) that make up its application programming interface (API):

  • Creation of processes/threads for the execution of programs
  • Orders of input/output (I/O)
  • Operations on files
  • Detection and treatment of errors in the operating system itself

Levels of an operating system

Multiprogramación and time-sharing

Depending on the number of processes and users that may run concurrently, an operating system can be:

  • Monotarea or monoproceso
  • Multi-tasking, multi-threaded or multiprogramación
    • Objective: maximize the utilization of the processor
  • Single-user
  • Multi-user or time-sharing
    • Goal: minimize response time

When a process needs to wait for an I/O statement, the processor can switch to a different process, this will get the multiprogramación

For that to be possible:

  • There must be a memory management to divide the main memory among multiple processes
    • Sharing multiplexed in space
  • There must be a planning to distribute the CPU time among the processes that are in memory
    • Sharing multiplexed in time
  • There must be protection mechanisms for the shared use of resources
    • The operating system allocates the devices to the processes and provides the I/O routines

Architecture Von Neumann

The architecture Von Neumann model (Von Neumann architecture or Princeton), is an architecture for computers based on that described in 1945 by the mathematician and physicist John von Neumann and others, first draft of a report on the EDVAC (Electronic Discrete Variable Automatic Computer)

Describes the architecture for the design of a digital computer electronic parts which consist of a processing unit that contains a unit arithmetic logic and processor registers, a control unit, which contains a record of instructions and a program counter, a memory to store both data and instructions, external mass-storage, and mechanisms for input and output

Von Neumann architecture

Processor registers

Program counter (CP)

Holds the address of the main memory of the next instruction that you have to load the control unit

Instruction register (IR)

Contains a copy of the current statement, obtained from the main memory

The process hardware

Sequence of read-and-running:

  • Read the instruction pointed by the program counter (CP)
  • Increase in the CP
  • Execution of the instruction, A computer only knows how to repeat it at great speed this sequence

You can break this linear sequence by modifying the value of the CP by:

  • Machine instructions jump
  • Interruptions internal interruptions)
  • External interrupts (exceptions)
  • Instruction trap (trap)

External interrupts

Commonly known as disruptions

An interrupt is a signal received by the CPU, indicating that it must interrupt its normal execution and to happen to execute specific code to treat this situation

It is the mechanism used by devices to request attention from the CPU:

  • Periodic interrupts of watch
  • Interruptions of the I/O devices

Treatment of interruptions

Hardware, cycle of acceptance of interruption:

  • Saves the context of the running process
    • Content of some processor registers
  • Raises the level of execution of the processor (by passing it to kernel mode)
    • Load a new value in the pc (jumps to the operating system)

For software, the operating system executes a routine treatment of the interruption

Interrupts internal

Also called exceptions, are unexpected events internal to the processor:

  • Arithmetic overflow
  • Division by zero
  • Invalid address
  • Attempt to execute a privileged instruction

Treatment of the exceptions

The management of exceptions is similar to that of the interruptions. Upon detection of the exception, transferring control to the handler of exceptions.The basic difference with the interruptions is that the exceptions tend to be handled in the user space. The operating system only notifies

Instruction trap (trap)

A user process performs a privileged operation by the instruction trap

Is an instruction in user mode generates an exception

Some call it disruption software, or also, call the supervisor (SVC)

It is invoked by a process that is running in user mode and you want to perform an operation that requires privileged instructions

Change the bit mode and branches to a fixed position of the space of the system

Dual-mode execution of the CPU

We call privileged instructions to those machine instructions that can potentially affect other processes:

  • I/O operations
  • Update the clock
  • Disable interrupts

Controlling the execution of privileged instructions we protect other processes and the operating system

Solution: To distinguish the two execution modes of the CPU

The processors now include a bit of mode that modifies the level of execution:

  • User mode
    • You can only run instructions are not privileged
    • The process only accesses to the user space
  • Supervisor mode or kernel
    • It can run any instruction
    • Is called a kernel (or kernel) of the operating system code that runs in this mode
    • Only the code of the operating system can run in supervisor mode and has access to both the system space as the user

Conclusion: The trusted software of the operating system runs in supervisor mode and the rest of the software runs in user mode

System calls

The system calls are procedures or functions provided by the operating system

Allow user processes to perform privileged operations

They are implemented through the instruction trap

  • The instruction trap is in need of an operand to reference a table from the core table (trap)

To hide the details of the instruction trap, the designer of the operating system provides a library of functions of “shelter”

  • The names of the functions guard coincide with those of the system calls
  • Each shelter contains an instruction to trap to the operating system function through the correct entry of the table of the trap to the kernel

Interface of system calls

Each operating system implements its own set of system calls that are exported through a call interface

This set of calls is the interface of the operating system with the application program or API (Application Program Interface)

The application programs invoke operating system services by calling the functions defined in the interface of system calls

The functions are implemented by various parts of the operating system: process manager, memory manager, device manager and file manager

Examples:

  • API standard POSIX on UNIX and Linux
  • Win32 API on Windows

POSIX

Standard interface operating system portable IEEE based on UNIX

Goal: portability of applications between different platforms and operating systems

It is not a deployment. Only defines a specification

Available in all versions of UNIX and Linux

Windows 2000 offers a subsystem of POSIX

Features

Function names short and in lowercase

  • fork
  • read
  • close

The functions normally return 0 if successfully executed, or -1 in case of error

  • Variable errno

Most of the resources managed by the operating system are referred to by descriptors: whole number greater than or equal to zero

Win32

It is not a standard

It is an API totally different from the POSIX standard

Defines the services offered by the systems Windows 95/98, Windows NT, Windows 2000 and Windows XP

It defines functions and graphic services

Features

Name of the functions long and descriptive

  • GetFileAttributes
  • CreateNamedPipe

It has predefined data types

  • BOOL
  • DWORD
  • TCHAR

The functions return, in general, true if the call was executed successfully or false otherwise

The resources are managed as objects,referenced by handlers

Design of the internal structure of the operating system

Monitor monolithic

All the operating system is designed as a single module composed by functions that can call each other

The user processes and the I/O devices communicate through the core

When code is executed by the monitor interrupts are disabled

Examples: MS-DOS, Windows XP, UNIX, Linux

Monolithic system

Microkernel

Some of the functions of the operating system are implemented as server processes in user

The kernel functions are reduced to a minimum, so that the reliability of the system increases

Examples: Minix, Mach, Windows NT

Microkernel system

Android

Android

Android is a mobile operating system based on Linux and open source software

It was designed for touchscreen mobile devices such as smartphones, tablets, Wear OS smartwatches, cars via Android Auto or Android Automotive, and televisions with Android TV

Android Logo

Both the name Android and Nexus One refer to the Philip K. Dick novel: Do Androids Dream of Electric Sheep?

Novel that was later adapted to the cinema as Blade Runner (1982)

Both the book and the movie focus on a group of androids called the Nexus 6 model replicants

The logo is the robot Andy

It was initially developed by Android Inc. and was acquired by Google in 2005

Android was introduced in 2007 along with the founding of the Open Handset Alliance (a consortium of hardware, software, and telecommunications companies) to advance open standards for mobile devices

The structure of the Android operating system consists of applications running on a Java object oriented application framework on top of the core Javo libraries in a Dalvik virtual machine with runtime compilation up to version 5.0, then switched to the environment Android Runtime (ART)

Libraries written in C language include a surface manager, an OpenCore framework, an SQLite relational database, an OpenGL ES 2.0 3D graphical API Programming Interface, a WebKit rendering engine, an SGL graphics engine, SSL, and a standard C Bionic library

The operating system is made up of 12 million lines of code, including 3 million lines of XML, 2.9 million lines of C language, 2.2 million lines of Java, and 1.77 million lines of C++

The main source code for Android (the source code was released by Google) is known as the Android Open Source Project (AOSP), which is licensed primarily under the Apache License, a free and open source license

History

In July 2005, the multinational Google buys Android Inc.

The announcement of the Android system was made on November 5, 2007 along with the creation of the Open Handset Alliance, a conglomerate of 78 hardware, software and telecommunications companies dedicated to the development of open standards for mobile devices

The same day the first version of the operating system is announced: Android 1.0 Apple Pie

Terminals with Android would not be available until 2008

Android smartphone unit sales ranked first in the United States in the second and third quarters of 2010, with a 43.6% market share in the third quarter

Worldwide, it achieved a market share of 50.6% during the fourth quarter of 2011, more than double that of the second largest mobile operating system (iOS from Apple, Inc.)

At the beginning of 2018, there were already more than two million applications available on Google Play Store, the official Android app store; to these should be added those available in other unofficial stores, such as Aptoide

Google Play is the online app store run by Google, although there is the possibility of obtaining software externally

The store F-Droid It is completely open source as well as its applications, an alternative to Google's proprietary software

The programs are written in the Java programming language, but it is not an operating system that is free from malware

Normally the different stores are safe (the one that is detected is persecuted and eliminated), therefore, most malware is downloaded from third-party sites

Acquisition by Google

In July 2005, Google acquired Android Inc., a small company Palo Alto (California), founded in 2003

Android co-founders who went to work at Google include Andy Rubin (co-founder of Danger), Rich Miner (co-founder of Wildfire Communications, Inc.), Nick Sears (once VP at T-Mobile), and Chris White ( who spearheaded the design and development of the interface at WebTV)

Back then, little was known about the functions of Android Inc. other than that they developed software for mobile phones

This gave rise to rumors that Google was planning to enter the mobile phone market

Also in that year the Android mascot was created: "Andy", as a green android symbolizing the literal translation of Android Inc.

The designer of the project was Irina Blok

Already at Google, the team led by Andy Rubin developed a platform for mobile devices based on the Linux kernel that was promoted by device manufacturers and operators with the promise of providing a flexible and upgradeable system

Speculation that Google's Android system would enter the mobile phone market increased in December 2006

BBC and The Wall Street Journal pointed out that Google wanted its search services and applications to work on mobile phones

Print and online media soon reported that Google was developing its own mobile phone

In September 2007, "InformationWeek" published an Evalueserve study that reported that Google had applied for various patents in the area of ​​mobile telephony

Open Handset Alliance

On November 5, 2007 the Open Handset Alliance, a conglomerate of various companies including Texas Instruments, Broadcom Corporation, Nvidia, Qualcomm, Samsung Electronics, Sprint Nextel, Intel, LG, Marvell Technology Group, Motorola, and T-Mobile ; was created in order to develop open standards for mobile devices

Along with the formation of the Open Handset Alliance, the OHA released its first product, Android, a platform for mobile devices built on the Linux 2.6 kernel

On December 9, 2008, it was announced that 15 new members would join the Android project, including PacketVideo, ARM Holdings, Atheros Communications, Asustek, Garmin, Softbank, Sony Ericsson, Huawei, Toshiba, Vodafone, and ZTE

On February 24, 2014, Nokia presented its smartphones (Nokia X, X+ and XL) running Android 4.1 Jelly Bean (although they used their own version, taking AOSP as the base)

Trade war between China and the United States

On May 19, 2019, Google officially announced that it was ceasing to provide service to Huawei mobile users in terms of updates and, in the future, to allow them to use its applications (Gmail, Google maps, etc)

There was a trade conflict between the US and China that led the US government to include the manufacturing company on the blacklist of collaborators with the Chinese government

This fact, which was a severe economic-business blow to Huawei, has raised serious doubts about the reliability of the Android system, since there were clear political and commercial motivations.

Given the dependence on the system, Google could in the future take similar actions against any type of device that uses it (via telephone, smart speakers, connected cars, etc.)

As well as generating commands not requested by the user or even spying on them through the connected equipment (cameras, microphones, etc.)

Dalvik replaced by ART

Android 4.4 introduced the ART (Android Runtime) as a new runtime environment, which compiles the Javo bytecode during the installation of an application

Until version 4.4.3 Android used Dalvik as a virtual machine with just-in-time compilation (JIT) to run Dalvik dex-code (Dalvik executable), which is a translation of Java bytecode

Following the JIT principle, in addition to interpreting most of the application code, Dalvik performs native compilation and execution of selected frequently executed code segments (footprints) each time an application is started

As of version 5.0 it became the only option at runtime

Update history

Android has seen numerous updates since its initial release

These updates to the base operating system typically fix bugs and add new features

Generally, each update to the Android operating system is developed under a codename of a candy related item in alphabetical order

The repeated appearance of new versions that, in many cases, do not work correctly on hardware designed for previous versions, make Android be considered one of the promoters of planned obsolescence

Android has been criticized many times for the fragmentation suffered by its terminals by not being supported with constant updates by different manufacturers

It was believed that this situation would change after an announcement by Google in which it announced that manufacturers will commit to applying updates at least 18 months after their release, but this never materialized and the project was canceled

Google is currently trying to rectify the problem with its upgradable platform Google Play Services (which works on Android 4.4 and later), separating all possible system apps (such as Maps, Gboard, YouTube, Drive, and even his own Play Store) to be able to update them independently, and including as few new features as possible in the new versions of Android

The versions of Android received up to version 9, the name of different desserts or sweets

In each version, the chosen dessert or sweet begins with a different letter, in alphabetical order:

Version history
Code Name Version Number Release Date API Level
Apple Pie 1.0 September 23, 2008 1
Banana Bread 1.1 February 9, 2009 2
Cupcake 1.5 April 25, 2009 3
Donut 1.6 September 15, 2009 4
Eclair 2.0 – 2.1 October 26, 2009 5 – 7
Froyo 2.2 – 2.2.3 May 20, 2010 8
Gingerbread 2.3 – 2.3.7 December 6, 2010 9 – 10
Gingerbread 2.3 – 2.3.7 December 6, 2010 9 – 10
Honeycomb 3.0 – 3.2.6 February 22, 2011 11 – 13
Ice Cream Sandwich 4.0 – 4.0.5 October 18, 2011 14 – 15
Jelly Bean 4.1 – 4.3.1 July 9, 2012 16 – 18
KitKat 4.4 – 4.4.4 October 31, 2013 19 – 20
Lollipop 5.0 – 5.1.1 November 12, 2014 21 – 22
Marshmallow 6.0 – 6.0.1 October 5, 2015 23
Nougat 7.0 – 7.1.2 June 15, 2016 24 – 25
Oreo 8.0 – 8.1 August 21, 2017 26 – 27
Pie 9.0 August 6, 2018 28
10 10.0 September 3, 2019 29
11 11.0 September 8, 2020 30
12 12.0 – 12L October 4, 2021 31 – 32
13 13.0 August 15, 2022 33
14 14.0 October 4, 2023 34

Android TV

Android TV

Android TV is a smart television operating system based on Android and developed by Google for televisions, digital media players, set-top boxes and sound bars

Successor to Google TV, it has a user interface designed around content discovery and voice search, aggregation of content from various applications and multimedia services and integration with other recent Google technologies, such as Assistant, Cast and Knowledge Graph

The platform was first introduced in June 2014, and was first available on the Nexus Player that November

The platform has been adopted as smart TV middleware by companies such as Sony and Sharp, while Android TV products have also been adopted as set-top boxes by several IPTV television providers

History

Android TV was first announced at Google I/O in June 2014, as a successor to the commercially failed Google TV

The Verge characterized it as more in line with other digital media streaming platforms, but taking advantage of Google's Knowledge Graph project; compatibility with Chromecast; a greater emphasis on search; closer ties with the ecosystem Android (including Google Play Store and integration with other families of Android, like Android Wear); and native support for video games, Bluetooth gamepads and the Google Play Games framework

Some attendees received the platform development kit, the ADT-1; The Information reported that the ADT-1 was based on a discarded “Nexus TV” launch device that was being developed internally by Google

Google unveiled the first Android TV device, the Asus-developed Nexus Player, at a hardware event in October 2014

The ADT-2 development kit device went on sale ahead of the release of Android TV 9.0

Android TV 10 was released on December 10, 2019, along with the ADT-3 development kit

Android TV 11 was released for the ADT-3 on September 22, 2020, while rollouts were planned for OEM partners in the following months

Features

The Android TV platform is an adaptation of the operating system Android for set-top boxes and as software built into smart TV hardware

Its home screen uses a vertically scrolling row-based interface, including a “content discovery” area populated by suggested content, followed by “Watch Now” rows that display media content from installed apps. Android TV supports entering voice commands and universal search across multiple services; some devices also support Google Assistant

All Android TV devices are compatible with Google Cast, which allows you to play multimedia content from compatible applications on other devices in an identical way to Chromecast

Android TV is compatible with Play Store software, including multimedia apps and games (although not all Google Play apps are compatible with Android TV)

Some Android TV devices, such as the Nvidia Shield and Razer Forge TV, are also marketed as microconsoles and include a wireless Bluetooth gamepad

Google TV interface

A modified Android TV user interface, branded “Google TV” (no relation to the company's smart TV platform that no longer has the same name), debuted on the streaming device Chromecast with Google TV, which was launched on September 30, 2020, coinciding with the rebranding of the video on demand (VOD) service of Google Play Movies & TV to Google TV on devices Android

The Google TV interface emphasizes content recommendations and discovery of different services and installed apps, compared to the Android TV interface, which focuses more on navigation between individual installed apps

Google TV is compatible with more than 6,500 applications created for Android TV

The Google TV interface replaced the Android TV interface in late 2022, and began being used on set-top boxes, dongles, and smart TVs in 2021

Streaming services in the United States
Service Operator
A&E A+E Networks
ABC American Broadcasting Companies, Inc.
Amazon Prime Video Amazon.com, Inc
AMC American Movie Classics
Apple TV+ Apple Inc.
BET+ Paramount Global, Tyler Perry Studios
Comedy Central Paramount Media Networks
Crackle Sony Group Corporation, Chicken Soup for the Soul
Crunchyroll Sony Group Corporation
DC Universe DC Entertainment, Warner Bros. Digital Networks
Discovery+ Warner Bros. Discovery
DisneyNOW Disney Channel, Disney Junior, Disney XD
Disney+ Disney Streaming
Fox Now Fox Corporation
FuboTV FuboTV Inc.
Funimation Funimation Films
Globoplay Grupo Globo
Hulu Disney+, ESPN+
HBO Max Warner Bros. Discovery
History A&E Networks
Kocowa+ wavve Americas (KBS, MBC, SBS, SK Telecom)
MGM+ Metro-Goldwyn-Mayer
MTV Paramount Media Networks
NBC NBCUniversal, RCA Corporation, Radio Corporation of America
Paramount+ Paramount Global
Paramount+ with Showtime Showtime Networks
Peacock NBCUniversal Cable Entertainment
Philo A&E Networks, AMC Networks Streaming,Paramount Streaming, Warner Bros. Discovery Global Streaming & Interactive Entertainment
Pluto TV Paramount Global
Sling TV Sling TV LLC
Starz Starz Inc
TBS Warner Bros. Discovery Networks
The CW CBS Entertainment Group, Warner Bros. Entertainment
TNT Warner Bros. Entertainment
Tubi TV Fox Corporation
VH1 Paramount Media Networks
Viki Rakuten Viki
Vix TelevisaUnivision, Vix
YouTube TV Google LLC

Devices

Televisions

During Google I/O 2014, Google announced that Sony, Sharp and TP Vision/Philips would launch smart TVs with built-in Android TV in 2015

It was noted that support for handling TV-specific functions such as input switching and tuning were natively built into the platform Android

Sony introduced a range of Bravia smart TVs with Android TV at CES 2015

Sharp launched two TV models on June 10, 2015

Philips announced that 80% of its 2015 TVs will run Android TV, with the first two models going on sale in June 2015

Google announced other TV hardware partners in January 2016, such as Arcelik, Bang & Olufsen, Hisense, TCL Corporation and Vestel

OnePlus has also launched several TVs that run on the Android TV platform; All OnePlus TVs run Android TV 9, except the newly launched OnePlus TV U1S, which runs Android TV 10

OnePlus' sister company Realme has also launched several TVs that run on the Android TV platform

TCL Corporation announced a range of smart TVs running Android 11 (and Google TV) at CES 2021

Other brands such as Mystic, Hisense, Motorola, and Xiaomi have launched their respective lines of televisions with this operating system

TV Box and TV Stick

In addition to televisions, external devices such as TV Boxes and TV Sticks that also have the Android TV operating system have also been launched, including the company NVIDIA, which launched the Nvidia Shield TV in 2015.

Other brands such as Mecool and Youin have launched devices such as the Mecool KM2 (which is certified by Netflix) and the Youin You-Box

Decoders

Several pay TV providers have launched IPTV services using Android TV-based hardware instead of a proprietary set-top box, such as Telekom Malaysia's Unifi Plus Box, LG Uplus's U+ tvG Woofer and U+ tvG 4K UHD, Freebox Mini 4K from the French ISP and BBox Miami from Bouygues Telecom

Dish Network launched an Android TV device known as AirTV Player in 2017, marketed as a companion to its Sling TV service, and which supports an optional adapter to connect an antenna and receive over-the-air television

Verizon Wireless, Tivo, and T-Mobile USA each offer a company-branded Android TV streaming dongle called Verizon Stream, TiVo Stream 4K, and T-Vision Hub, respectively

In 2020, AT&T launched AT&T TV as its new flagship pay television service, which is based on an Android TV decoder and the infrastructure of its OTT service DirecTV Now

Ericsson added support for Android TV to its MediaFirst IPTV platform, which is used as the basis for Canadian services such as Telus Pik TV and SaskTel MaxTV Stream

Vodafone Australia currently sells a TV tuner and media streaming device with Android TV, but as of 2020 it has been discontinued

The GNU / Linux system

The file system GNU / Linux

GNU / Linux is based on UNIX file system, which has a tree structure. The point of origin is called root and is represented with the symbol /

Un sistema GNU / Linux puede ser instalado en una "única partición" o en múltiples particiones. Existiendo la partición especial para el intercambio con la memoria, la partición swap. Esta partición permite al sistema usar el disco cuando agota la memoria

Underneath the root (/), hang all the system directories. Really root hangs the system root partition that contains the basic files for the boot and operation of the system. The other partitions, we can establish hang of directories

It is possible to have in different partitions, user files, user applications, files, of variable length, temporary files. The multiple partitions allow us to better manage the system

We can create backup copies of all of the parts that interests us or limit the use of certain parts to a particular user. In this way we prevent the disk from filling up completely, as the only one that has write permission on the partition root is the administrator user

The type of partition most used in GNU / Linux systems is the ext2 or ext3. The units are not fixed, such as cd-rom, blu-disk, zip, pendrive, etc, hang on different directories with a descriptive name that refers to them, within the directory /mnt

The description of the properties of each partition is done in the file /etc/fstab

Name of files

A valid filename for the Linux kernel can contain any character except the characters ‘/’ (bar) or ‘\0’ (void)

Sin embargo no es prudente usar caracteres especiales usados por la shell (la línea de comandos) tales como ($, ", ‘, &, #, (, ), *, [, ], {, }, …). Tampoco debe empezar por el carácter ‘-‘ que puede ser confundido con una opción

When a user is created, the shell defines the default which will use the input directory named like the user name. The value of this directory entry can be found in the system variable $HOME

In each directory there are at least two accessible entrances, which are ‘.’ (reference to the current directory) and ‘..’ (a reference to the parent directory). In the $PATH variable stores the reference to the subdirectory current. If you want to run commands contained in the current directory, use the command

The ‘/’ character is used to separate the different levels of directories within the file name

When the file name begins ‘/’ then we are stating the full path name or the name of the absolute path. If on the other hand starts with ‘./’ or ‘../’, then we are indicating a name of the relative path, because we are using the subdirectory current where we are. The last part of the name after the last ‘/’ character is the name base name

The files that start with ‘.’ are not considered and therefore are considered to be hidden to the system, except that certain commands are directed. For example, to list a directory using the ls command, but starting with ‘.’ does not list them in the list despite being the files the same as the rest

The system identifies internally the files with a number, which is called the number of i-node. In the i-node are saved for different properties of the file such as:

  • file type
  • id of the owner
  • id of the group owner
  • number of links
  • its size
  • date of last access
  • date of the last modification
  • date of change of the number of i-node
  • an array with the data blocks that holds the file

Types of files

  • Regular: mere stores of information. Some contain executable code
  • Directories: table that contains the numbers of i-nodes and the names of all the files contained in the within the directory
  • Special files: can be a device of type character or block device. The handling of these files depends on the particular device
  • Symbolic links: files that contain a pointer to another file that could be stored in a different filesystem
  • Hard links: file which can be seen with different names within the file system (similar to aliases). That is to say, we can list them as if they were files identical but that share the same i-node. The information resides in one place and the changes made in a file also occur in the other equivalent. Links of this type do not work with file systems different, have to be of the same type. Not all file systems support hard links, as that is a concept very much tied to UNIX-like operating systems

The directory tree

The directories and files of the GNU / Linux systems are standardized in a document called the FSSTND. Among the various distributions of Linux we can find some differences

We will describe the main directories defined by the standard and what it contains:

  • /bin: basic commands of the operating system
  • /boot: boot files, including the file of the kernel that has the form vmlinuz-x.x. x x.x
  • /dev: device files
  • /etc: configuration files of the system
  • /etc/X11: configuration files for the X Windows (libraries for the management of the graphical environment, like Windows)
  • /home: directories of the users. By default the same name as the user name
  • /initrd: directory for the boot process
  • /lib: libraries necessary for the implementation of the resident programs in the directories /bin and /sbin
  • /mnt: to mount the removable devices (Cd-Rom, Blu-Disk, Zip, pen drive, ...)
  • /proc: houses special files for that, or collect information from the kernel, or the provide. The files generate the information when you view them
  • /root: home directory of the super user administrator (has all permissions on the system)
  • /sbin: contains executable files that can only be run by root root
  • /tmp: are saved to temporary files
  • /usr: files that can be shared throughout the system. It is the place in which you are installing the user applications. Contains directories such as /usr/bin, /usr/sbin, /usr/lib, /usr/man, /usr/X11R6, ...
  • /usr/local: it is for the exclusive use of root, to the installation of particular software of the machine, the peripheral drivers
  • /var: ficheros de longitud variable. Esto incluye los directorios y ficheros de "spool", datos de administración y registro, así como ficheros transitorios y temporales que no se guarden en el directorio /tmp

To move in the path of directories we use the cd command. For example, if we want to access the directory man, write in the command line cd /usr/man

File permissions

Files have many attributes in addition to its name. To see the more significant when we run the ls -l

Numeric notation for permissions

The permissions of the files are stored in binary format and can be referenced numerically. To do so is given the value 4 to the read permission, the value 2 to the write permission and 1 for the execute permission. Then summed the values for user owner, group, and user either, getting a three-digit number. Let's look at an example:

Other permissions

There are also permissions SUIG and SGID, that allow to identify when a program is executed by the owner of the file or the group of the file instead of the user that has launched. In general it is used when the root wants to give permission for execution of one of its programs to another user

Another permission is the sticky bit, or townhouse (bit sticky), it is for the process to stay in RAM memory while it runs. It uses little

The numerical values for the SUIG are 4, for the SGID is 2, and for the bit sticky is 1, added in front of the other 3 values of permissions. As well, we could give to our program, the permit 4751

Command for permissions

The command to change permissions is chmod, and supports numeric format or character format. In the character formatting is used u (user), g (group), o (other) and to (all) to indicate to whom they affect. The symbols + (for adding permissions), – (for removing permissions), = (set permission). Finally, r (read), w (write), x (execution) s t (bit sticky)

Permissions for the directories

To understand how the permissions applied to a directory it is necessary to imagine that a directory is a regular file that only contains a table that lists the files present in that directory. In each directory there are always a couple of entries that are ‘.’ (for the current directory) and ‘..’ for the parent directory. The permission of execution is understood as access

If a directory does not have read permission, it will prove impossible for any command, including ls, read your content

If a directory does not have execute permission, will not be able to cd to that directory, or any of the subdirectories that hang of it. This makes it impossible all the operations that use that directory as part of the road

If you do not have write permission may not be given high, low, or modifications in the table, that is to say, you can not delete files nor create new ones, or rename them

Finally, in a directory, the bit sticky is understood as that it is protected before the creation of the same file by different users, even if they have sufficient permissions. It is usually applied to the /tmp directory

Other related commands

  • umask: sets the default permissions for creation of files
  • chown: allows you to change the user owner of a file or several files
  • chgrp: allows you to change the group owner of a file or several files

How to run UNIX commands

UNIX commands follow the following structure:

box_unix

The standard input is usually a file or the keyboard. The standard output is usually the screen, and the output of the standard error is also the screen

The format of the command follows the structure:

  • order: the name of the command
  • -: the minus sign indicates that it is an option
  • options: one or more characters of options
  • arguments: are literal, taken as input parameters for the command

Redirection and connections

Both the outputs as a standard input you can redirect to a file or device (remember that from the point of view of the system all are files)

We may also pass the standard output of one command to the standard input of another, using the connection

For these operations we use the following metacharacters for the shell:

> command >file directs the standard output to the file
>> command >>file appends standard output to file
< command <file extracted file to the standard input
<<str follows the standard input until the next str in the line
p1¦p2 connects the standard output of p1 to the standard input of p2

The connections give a great power to the system, as, although it is a command by itself, then a trivial task, when combined with others become the tools of general and useful. This allows us to easily create new commands and that the growth of the system is limited only by our ability of creation

Other metacharacters of the shell

* matches any string of zero or more characters in the files
? matches any single character in the file
[ccc] match any single character from ccc in files, are valid ranges 0-9 or a-z
; p1;p2 when the command p1 runs the command p2
& as ; but do not expect it to end p1
`...` run command in ...; output replaces `...`
(...) run command ... in a subshell
$1, $2, ... we replace the arguments in a file of the shell
$var value of the variable var in the shell
${var} value of the shell variable var avoids confusion when concatenating with text
\ \c it literally takes the character c
‘...’ it takes ... literally
"…" se toma … literalmente después de interpretar $, ‘…’ y \
var=value it assigns the value to the variable var
p1&&p2 p1&&p2 run p1if it succeeds, run p2
p1¦¦p2 p1¦¦p2 run p1 if this is not accomplished, run p2

UNIX commands

We're not going to expose here is a list of UNIX commands, explaining their functionality.

In the first place because there are multiple pages dedicated to it, and in the second place by the system itself provides us with multiple aids on them

With the man command you can get help from any program or setup file, if we want to know how it works, it can call itself in the following way: man man

When we do not know the name of a command we can use the command apropos, and to indicate something related to it

Another help command is the info command. This command usually complete the help of man

Many commands give help among its options by running the command

Another source of help are the HOWTOs. Are tutorials on how to perform certain operations in the system. Are published by The linux documentation project (The Linux Documentation Project) and available in many languages

Some packages include own documentation in a subdirectory of /usr/share/doc that has the same name as the package

Note: do not forget that with the tab key, the shell completes the file names, which helps to locate the commands and files even if we don't remember his full name. In addition to avoid many errors when typing

The Linux shell

The Linux shell

A shell or command interpreter is a program interface that allows a user to write instructions to the operating system. In the Linux environment there are three major families of shells: sh, csh and ksh. The bash shell (Bourne Again Shell) belongs to the family sh

One of the main features of a command interpreter is that it can be programmed using text files that contain commands that are to be interpreted in the execution of the same

These text files are called files commands or scripts (also scripts, shell scripts or scripts shell). Therefore, a file of commands is a text file executable that contains commands that can be interpreted by the shell

Features

The first line of the file indicates the type of shell that must be interpreted, in our case bash:

Each line of the file contains a command that will be executed by the interpreter

If you want to run multiple commands on the same line must be separated by ‘;’

To continue a command in the next line it must end with '/'

The ‘#’ character at the beginning of a line indicates that it is a comment and therefore the interpreter will not execute it

To display text or variables on the screen, use the echo command

Variables

Each shell has associated with some variables, that the user can use. There are two types of variables:

  • Local Variables: Are not inherited by the child processes of the shell when doing a fork
  • Environment Variables: Are inherited by the child process when a fork

All variables are preceded by ‘$’

Use of variables

To define a new variable or a value to a variable use the =operator

As we have mentioned before, to display on the screen the value of the variable use the echo command

To convert a local variable into an environment variable use the export command

To delete a variable and its value from memory, use the command unset

To display all variables (local and environment), we will use the set command

To show only environment variables, use the command env

We can use the following environment variables pre-defined within the shell

$HOME Home directory of the user
$PWD Working directory of the user
$PATH Absolute path of directories to search for executables. The working directory of the user is not included by default
$PS1 Prompt main shell
$PS2 Prompt secondary
$IFS Internal separator Field. Used by the command internal read

Arguments

Like any program, a script can receive values through arguments or parameters, in the command line. The arguments received are stored in a series of variables that the script can use

$1 The first argument
$2 The second argument
$3 Third argument
$4 Fourth argument
$5 Fifth argument
$6 Sixth argument
$7 The seventh argument
$8 Eighth argument
$9 Ninth argument
$C Name of the script
$* String containing all the arguments
$# The number of arguments received by the script
shift To move all arguments to the left position. That is to say, the value $1 disappears and is replaced by the $2, and so on

Quotes

Simple ‘ ‘

String of characters that the shell takes literally

Reverse ` `

Must enclose a complete command (with its name and its arguments) produces a run in three phases:

  1. Evaluation of variables
  2. Substitution of the command for a string that contains the standard output of the command
  3. Execution of the result

Dobles " "

Allow the evaluation of variables and command substitution

Commands flow control

Sentence if

expression can be a comparison expression or a command. Its value will be the one that returns the expression or the execution of a command

To enter by the branch that follows then, expression must have returned a 0 (true) and to enter an elif branch or an else branch, expression must have returned a value other than 0 (false)

Expressions

If we want to compare two values we must use the test

test evaluates the expression. If this is true it returns code 0 and if this is false a code other than 0

The most common expressions are:

-r file true if the file exists and has read permission
-w file true if the file exists and you have write permission
-x file true if the file exists and you have execute permission
-f file true if the file exists and is a file
-d file true if the file exists and is a directory
-s file true if the file exists and its size is greater than 0
-z string true if the file exists and its size is 0
-n string true if the file exists and its size is different from 0
string1 == string2 true if string1 is equal to string2
string1 != string2 true if string1 is different from string2
string true if string is not the null string
n1 -eq n2 true if n1 is equal to n2
n1 -ne n2 true if n1 is different than n2
n1 -gt n2 true if n1 is greater than n2
n1 -ge n2 true if n1 is greater or equal to n2
n1 -lt n2 true if n1 is less than n2
n1 -le n2 true if n1 is less than or equal to n2

These expressions elementals can be combined using parenthesis and the following operators:

! negates the expression
-to is equivalent to the AND operator
-or is equivalent to the OR operator

Case statement

Compares the string with the patterns, executing the list of commands corresponding to the first pattern with which it agrees, after which the execution of the case statement ends. A pattern can include any of the metacharacters of the shell

* is the default pattern and runs when none of the others

For statement

The list of commands is executed as many times as items are in the list. Before each iteration the next value of the list is assigned to variable, starting the first iteration by the first value

It is very useful if we want to go through all the arguments

Sentence while

command_list runs as many times as true expression

Judgment until

command_list is executed as many times as false expression

OR operator

command1 is executed; if it returns an error code other than 0 then the command2 is executed, and the code it returns is the code returned by the complete command; if command1 succeeds (code 0) then command2 is not executed and all expression succeeds

The previous example checks to see if the fich1 file exists. If it exists, nothing is done, otherwise a message is displayed by the standard error channel

AND operator

command1 is executed; if it returns an error code equal to 0 then the command2

In the example checks to see if there is a directory called dir1. If it exists, the content is displayed, otherwise nothing is done

Note: there is an operator object command

Read command

value_list are variables separated by a space

The execution of the read command reads from its standard input a line of text divided into words (i.e. strings separated by blanks or tabs)

Assigns the first word to the first variable, the second to the second variable, and so on until you complete the value_list

If not entered enough words, to the variables remaining to be assigned the null string

If in the line there are more words than variables, then it is assigned to the last variable a string consisting of all the words leftovers

Example of trace line to line of a file

Exit command

All command returns a code to notify the end if its execution has been correct or if it has appeared an error. If the execution has been correct, it returns error code 0, and if there has been any problem it is returned as a code any positive number

The files command returned at the end of a code error; the exact error code returned by the last command in the file that is running. To modify this situation by default we have to use the exit command

Where the optional argument n will be an integer greater than or equal to 0. If you do not specify an argument is equivalent to exit 0

When running the exit command, it immediately terminates the execution of the file command and is returned as an error code the integer n

Linux User

Linux User

Each Linux user is identified to the system with a user name because that is a multi-user system

To this name the system associates a unique number (UID), a password, your full name, a boot directory (the home user) and a login shell (there are different shell programs, and choose between one or the other according to the characteristics of the user or the type of shell you prefer)

All these data saved the system in the /etc/passwd and /etc/shadow. The /etc/shadow file contains the encrypted password and data over the same (such as the validity time, in days to warn before expiry, every time you have to force your change, etc). The creation of this file came as a matter of safety, as the file passwd must be accessible to all users

Structure

The structure of the file passwd is the following:

user Not supported numbers at the beginning of a user name
x An “x” indicates that the password is stored in /etc/shadow, in the case of a “!” is that the user is locked. “!!” indicates that it has no password
uid Each user has an assigned id number (uid) between 0 (root) and 65535. Reserved for special users, such as root (which is always zero) and for users of services of the system. Systems-Red hat and derivatives between 1 and 499. In Debian systems and derivatives between 1 and 999
gid Each user is assigned a number id of the primary group (gid), that is to say, always belongs to at least one group, but can belong to more than one group
full name This option is designed for the user to enter their full name, although it can also be used to write a description of what makes that user or which is its usefulness, in the case of a service system
home directory Is the home folder that the user will use by default when you start your session
shell command The users associated with a system service, or users with limited permissions should not have a shell command, that is to say, ability to login in console mode, normally, this field is populated as /usr/bin/nologin or /bin/false

Some of the most common can be found in the following table:

User UID GID Home directory Terminal
root 0 0 /root /bin/bash
bin 1 1 /bin /sbin/nologin
daemon 2 2 /sbin /sbin/nologin
adm 3 4 /var/adm /sbin/nologin
lp 4 7 /var/spool/lpd /sbin/nologin
sync 5 0 /sbin /bin/sync
shutdown 6 0 /sbin /sbin/shutdown
halt 7 0 /sbin /sbin/halt
mail 8 12 /var/spool/mail /sbin/nologin
news 9 13 /var/spool/news
uucp 10 14 /var/spool/uucp /sbin/nologin
operator 11 0 /root /sbin/nologin
games 12 100 /usr/games /sbin/nologin
gopher 13 30 /usr/lib/gopher-data /sbin/nologin
ftp 14 50 /var/ftp /sbin/nologin
nobody 99 99 / /sbin/nologin
vcsa 69 69 /dev /sbin/nologin
rpm 37 37 /var/lib/rpm /bin/bash
wnn 49 49 /var/lib/wnn /bin/bash
ntp 38 38 /etc/ntp /sbin/nologin
nscd 28 28 / /bin/false
apache 48 48 /var/www /bin/false
mysql 27 27 /var/mysql /bin/bash
mailnull 47 47 /var/spool/mqueue /sbin/nologin
smmsp 51 51 /var/spool/mqueue /sbin/nologin
rpc 32 32 / /sbin/nologin
xfs 43 43 /etc/X11/fs /sbin/nologin
gdm 42 42 /var/gdm /sbin/nologin
rpcuser 29 29 /var/libs/nfs /sbin/nologin
nsfnobody 65534 65534 /var/libs/nfs /sbin/nologin
ident 98 98 / /sbin/nologin
radvd 75 75 / /sbin/nologin
sshd 74 74 /var/empty/sshd /sbin/login
postgres 26 26 /var/lib/pgsql /bin/bash
squid 23 23 /var/spool/quid /dev/null
named 25 25 /var/named /bin/false
pcap 77 77 /var/arpwatch /sbin/bash
amanda 33 6 /var/lib/amanda /bin/bash
mailman 41 41 /var/mailman /bin/false
netdump 34 34 /var/crash /bin/bash
ldap 55 55 /var/lib/ldap /bin/false
postfix 89 89 /var/spool/postfix /bin/true
privoxy 100 101 /etc/privoxy
Pvm 24 24 /usr/share/pvm3 /bin/bash

Add

The command to add a user is useradd

In the example we created the patxi user who belongs to the users group and ftp, has as shell /bin/shell, we assign the password key and their home folder will be /home/patxi

This command supports the following parameters:

-d User's home directory
-s The user's Shell
-p Password
-g Primary group to which we assign the user
-G Groups which the user belongs
-m We force the creation of the directory in your home

In the file /etc/default/useradd saved default settings for the useradd command and in the directory /etc/skel are the files and directories by default will be in the user's home directory when you create it

Edit

The command to modify users is usermod

In the example we have modified the user patxi who belonged to the group users and ftp, now his main group is a server, although it still belongs to the groups users and ftp

This command supports the following parameters:

-d To modify a user's home directory
-s Modify the user's shell
-p Modify Password
-g Change primary group to which we assign the user
-G Modify groups which the user belongs

Delete

The command to delete users is userdel

In the example deletion by user patxi and in addition we have forced to delete the contents of your home when you use the-r parameter, if we had not used, would still exist

Change the key

The command to change the key of a user is the passwd command. Keep in mind that you must have sufficient permissions to be able to make the change, either because of who is running the command is the user or the superuser root

If we want to change the password of the root user, and we have sufficient permissions, can be done by leaving the parameter empty user

shadow

The structure of the file shadow is the following:

user Name of the user
encrypted password The password with a strong encryption
1 Days since 1-1-1970 where the password was changed for the last time
2 The minimum number of days between password changes
3 Maximum days of validity of the account
4 Days of warning before password expires
5 Days after a password expires to disable account
6 Expiration date. days since 1-1-1970, where the account is deshabilatada and the user will not be able to log in

Groups Linux

The users are grouped into groups. The groups are also identified by a name and the system associates an identification number (GID). Every user has a primary group, but can belong to multiple groups, which inherits its privileges. Groups allow you to give the rights and restrict options globally to multiple users

The relationship of the groups is saved in the file /etc/group. There is also the file /etc/gshadow for encrypted passwords of group, although it is not very used

Structure

The structure of the group file is the following:

group The name of the group (it is recommended that you do not have more than 8 characters)
x An “x” indicates that the password is stored in /etc/gshadow
gid Each group is assigned a number identifier (gid) between 0 (root) and 65535 (the gid 0 to 499 are reserved by the system), so it will start numbering from 500
members list List of the members of the group, separated by commas (without spaces)

Some of the most common groups can be found in the following table:

Group GID Members
root 0 root
bin 1 root, bin, daemon
daemon 2 root, bin, daemon
sys 3 root, bin, adm
adm 4 root, adm, daemon
tty 5
disk 6 root
lp 7
mem 8
kmem 9
wheel 10 root
mail 12 mail
news 13 news
uucp 14 uucp
man 15
games 20
gopher 30
dip 40
ftp 50
lock 54
nobody 99
users 100
slocate 21
floppy 19
vcsa 69
rpm 37 rpm
utmp 22
wnn 49
ntp 38
nscd 28
apache 48
mysql 27
mailnull 47
smmsp 51
rpc 32
xfs 43
gdm 42
rpcuser 29
nfsnobody 65534
ident 98
radvd 75
sshd 74
postgres 26
squid 23
named 25
pcap 77
wine 66
Mailman 41
netdump 34
ldap 55
postdrop 90
postfix 89
privoxy 101
pvm 24

Add

The command to add groups groupadd

In the example we have set the group server with a gid of 500, in case you do not put anything you would use the greater than 500 is not used by another group. You can use the-g parameter to set the gid manually

If you want to add existing users to the newly created group will use the gpasswd command

In the example we added the user patxi with the parameter -a to the group server

Edit

The command to change groups is groupmod

In the example we have modified the gid to 501 of the group server

This command supports the following parameters:

-g Change gid of the group
-n Modify the name of the group

This command only makes changes in the file /etc/group, so the rest of
modifications involved in changing the gid of a group, you have to do manually in the files /etc/passwd and /etc/gshadow

Delete

The command to delete a group groupdel

In the example deleted the group server

You cannot delete a group that is a initial group for any user, without first deleting the user

The command does not traverse the file system looking for files owned by the group. If
we want to remove them, we have manually or with command-deletion of files

If we want to delete existing users to the newly created group will use the gpasswd command

In the example we have removed the user patxi with the-d parameter of the group server. But this will not delete the home directory of the group

Process of the operating system

Process

A process is a unit of processing managed by the operating system (it is a program in execution)

The operating system implements a collection of abstract machines

Each machine is a simulation of the hardware of the von Neumann underlying

The process manager creates the environment in which coexist various processes. Each one runs in its own abstract machine as a multi-tasking

A resource is any element of the abstract machine that can be requested by a process

A process requests a resource by making a system call, which can cause it to crash if it is not available

The reservation of the resource causes the resource to be part of the configuration of the abstract machine in the process

Examples of resources: processor, main memory, I/O devices, files

Tables of the operating system

The operating system maintains tables that describe the processes and resources of the system:

  • Process tables: tables of BCPs
  • Tables of memory: information on the use of the memory
  • Tables of I/O: information associated with the peripherals and the I/O operations
  • Tables files: information about the files open

Operating system tables

Memory image of the process

A process address space is the set of logical addresses that can be routed

On computers 32 bit the max is 4 GB

On 64 bit computers, the maximum is 128 GB, however, at present there are no plates that support memories so great

The memory image of the process is the block of physical memory assigned to the process

The address space of the process is limited to the block of physical addresses corresponding

The address space is important for the protection of resources against unauthorized access

State of the processor

When running, the processor state resides in the processor logs:

  • General records
  • PC
  • Stack pointer (SP)
  • State records
  • Special registers

When it does not run, its processor state resides in the BCP

Change of context

When an outage occurs:

  • Saves the state of the processor at the corresponding BCP
  • It starts executing the routine treatment of interruption of the operating system

Scheduler:

  • Module of the operating system that selects the next process to run

Dispatcher:

  • Module of the operating system that makes running the selected process

Process Control Block (PCB)

Information process identification

  • Process and parent ID (pid, ppid)
  • Actual and effective user ID (uid, euid)
  • Actual and effective group ID (gid, egid)

Information of the state of the processor

Information of control of the process

  • Information for planning and status
  • Description of the address space
  • Assigned resources (open files, ports, ...)
  • Communication between processes
  • Pointers for structuring the processes in lists or queues

Process Control

Process Control

Process control allows us to talk about execution, threads or threads, which are a sequence of tasks chained so small that they can be executed by an operating system

Process model with two states

A process can be in one of two basic states:

  • Execution
  • No execution

Two-state process

Processes not running

With a single queue of non-running processes, the scheduler would have to traverse it to find a process that is not blocked. FIFO (First-in, First-out) strategy is not used

Two types of non-execution processes:

  • Ready to run
  • Locked: Expect to complete an I/O operation

Model of five states

  • Execution
  • Ready
  • Locked
  • New
  • Finished
  • Five-state process

    Processes suspended

    The operating system may decide to “evict” a process from main memory and transfer it to disk

    Two new states:

    • Locked/Suspended: The process is in secondary memory waiting for an event
    • Ready / Suspended: The process is in secondary memory available for execution

    Two-state sleep process

    Signals and exceptions

    Signals and exceptions are the mechanisms that uses an operating system to notify a process of the occurrence of a particular event

    The signals are used in POSIX and exceptions are used in Windows

    Signals

    A signal is the interruption of a process

    Receiving the signal:

    • The process stops its execution
    • Branches to execute a signal processing routine (code must be part of the process itself)
    • Once the processing routine is executed, follow the execution of the process

    Sending the signal:

    • The source can be the operating system or a process
    • At POSIX, it is done using the kill service

    Exceptions

    Event that occurs during the execution of a program and that require the execution of a piece of code outside the normal flow of execution

    Can be generated by the hardware or the software

    Exception handling requires programming language support. For example, in Java:

    Threads

    A modern process manager separates dynamic execution from static aspects of the computational environment from the process:

    • Modern process: Unit of resource ownership
    • Thread (or light process): Unit or engine running

    A process can contain a single ground thread or several threads of execution

    States of a thread

    States:

    • Execution
    • Ready
    • Locked

    The state suspension belongs to the concept of process

    Basic operations related to thread state change:

    • Creating/destroying a thread
      • When you create a process, you also create a thread
      • A thread of a process can create other threads within the same process
    • Lock/Unlock
      • Reservation-specific resource from the thread

    Processes in a multi-threaded environment

    Own information for each thread:

    • Processor Logs: counter, battery, status, etc.
    • Thread Status: Execution, Ready or Locked

    Information shared by all threads in the same process:

    • Address Space: code and data
    • Global Variables
    • Open files
    • Other shared resources

    Benefits of threads

    Facilitates modularity by allowing you to encapsulate each task in a thread independent

    Increases job execution speed:

    • It takes less time to create/finish a new thread than a process
    • It takes less time to switch context between two threads of the same process
    • Because threads in the same process share memory and files, they can communicate with each other without invoking the kernel

    Allows concurrent programming

    Process server

    A server is a process that is pending receiving work orders that come from other processes (clients)

    Once the order is received, it executes it and responds to the customer with the result

    Communication between the client process and the server is done through the ports

    Daemon

    They are booted when you start the system. They are always active and do not die

    Running in the background and are not associated with a terminal or login process

    They are typically waiting for an event or perform a task periodically

    They don't do the work directly: they throw other processes (or threads) to do their homework

    Examples: FTP server, web server, ...

POSIX process management

POSIX process management

Identification of processes

POSIX identifies each process by a unique integer called the process id of type pid_t

The function to get the id of the process that performs the call is

The function to get the id of the parent process is

The function to get the id of the real user is

The function to get the id of the actual group is

Environment of a process

The environment of a process consists of the list of variables that are passed to the process at the time you start your run

They are accessible through an external variable that points to a list of environment variables:

Some environment variables:

  • HOME: working directory initial user
  • LOGNAME: name of the user associated with the process

The function to get the value of an environment variable is char

Creation of processes

The function to create a process is

Returns the id of the child process to the parent process and 0 to the child process, will return -1 in case of failure

Creates a child process that runs the same program as the parent. Inherits open files (descriptors are copied)

The functions for running a different program (code) are:

As arguments path, executable file file and arg are used as executable arguments

Returns -1 in case of error. If successful it will not return any value

Changes the memory image of the process. The same process runs another program but keeps the files open

Termination of processes

The function to terminate a process is

As an argument state is used, which is the return code to the parent process

Ends the execution of the process

Closes all the file descriptors open

All the resources are released in the process

Waiting for the terminaciçon of a process

The functions to wait for the completion of a child process are:

As arguments state, the termination identifier of the child process, pid, process identifier, options, options identifier are used

Returns the identifier of the child process or -1 in case of error

Allows a parent process to wait until the end of the execution of a child process

Example program

Planning

Planning

You need to make a planning to determine what will be the programs that are supported in the system

Types of planning

  • Long term planning: Decision to add processes to set of processes to run
  • Medium term planning: Decision to add processes to set of processes that are partially or fully in memory
  • Short term planning: Decision on which available process/thread will be executed on the processor

Long term planning

Determines which programs are supported on the system. You must make two decisions:

  • When you can create a new process
  • What will be the next process to support. Combine processes with higher processor load and processes with higher I/O load

Controls the degree of multiprogramming. The more processes that are created, the lower the percentage of time each process can run

Medium term planning

Part of the function of exchange

It is based on the need to control the degree of multiprogramación

If virtual memory is not used, you should consider the memory needs of the process

Short term planning

CPU Usage Planning: Manage CPU Sharing Between Processes/Threads Ready to Run

The goal of the scheduler is to divide the processor time among the processes/threads that can run

You should consider factors such as:

  • Equity: spread out the CPU usage
  • Efficiency: avoid time idle CPU
  • Performance: to maximize the number of requests

Planning mechanisms

The scheduler consists of three logical components:

  • Queue: When a process changes to the Ready state, the gluer places it in a queue-type data structure
  • Context Switch: When a process is to be evicted from the CPU, the context switch saves the contents of the CPU logs in the process BCP
  • Distributor: The dealer selects one of the processes in the queue of Ready and assigns the CPU

Planning queue diagram

Criteria of the planning

Criteria for comparing the performance of the various planning algorithms:

  • Time of service (T_s) Estimated time of execution
  • Time of return (T_r) Elapsed time from the time it arrives at the system until it ends
  • Waiting time (T_w) Sum of times that the process is not running
  • Return time normalized (\frac{T_r}{T_s}) Return time divided by the time of the service

Use of priorities

The planner will select always to a process of higher priority before than the lower priority

Uses multiple queues of Ready-to-represent each level of priority

Lower priority processes can be starved (never chosen)

A solution to starvation is to allow a process to change its priority based on its age or execution history

Planning policies

They rely on a selection function to determine which process, from among the Ready, is chosen to execute

The function can be based on priorities, resource needs, or process execution characteristics

There are two kinds of algorithms depending on the decision mode (instant the selection function is applied):

  • No expulsion (non-appropriation or non-preferred): Once the process goes into the Execution state, it continues to run until it terminates or crashes waiting for an I/O (burst)
  • With expulsion (appropriate or preferred): The process that is currently running can be interrupted and passed to the Ready by Operating System state. They allow to give a better service since they prevent a process from monopolizing the processor for a long time

Planning algorithms

Algorithms without ejection:

  • FIFO (First-come First-served): First to arrive, first to be served
    • Select to run the process the more ancient of the queue of Ready
    • Easy-to-implement
    • Average waiting time very high
    • Penalizes short processes on the long-term processes
    • Favors the processes with CPU load of the processes with I/O load
    • It is often used combined with priorities
  • SPN (Shortest Process Next): First, the short process
    • Selects the process with the shortest time of service
    • Difficulty in estimating the expected time of execution for each process
    • Minimizes the average waiting time
    • It penalizes those processes over the short processes
    • Possibility of starvation for long processes

Algorithms with ejection:

  • Round Robin (RR)
    • Uses a time quantum that is a fraction of the time that allows each process to use the CPU
    • Ejects the process that has consumed its quantum of time and happens to occupy the last place of the queue of Ready
    • There are difficulties in choosing the size of the quant (less than 80% of CPU bursts)
    • Favors the processes with CPU load of the processes with I/O load
    • The large timeout, but ensures a CPU distribution with good response times
  • FB (Feedback): Feedback multilevel
    • Divide the Ready queue into a queue hierarchy: RQ_0, \cdots, RQ_n, each with a priority level
    • Uses a time quantum, and a dynamic mechanism of priorities
    • The processes fall by RQ_0 and in each execution burst descend to the next queue
    • FIFO is used in each queue, except for the lower priority that is treated with a rotating shift
    • Favors short processes in front of the most old and long
      • Short processes will end quickly, without descending too low in the queue hierarchy
      • The long-term processes will be gradually brought down
    • There is a great number of variations of this scheme
    • To avoid starvation of long processes can be varied as a function of each queue

    Planning on POSIX

    Each planning policy has an associated range of at least 32 priority levels

    The scheduler will select the process with the highest priority

    When a process is ejected by a higher-priority process, the process becomes the first in the queue associated with its priority

    Three planning policies coexist in the planner:

    • SCHED_FIFO: It is an expulsion planning policy based on static priorities, in which processes with the same priority are served on the first come, first-served basis (FIFO queue). This policy will have at least 32 priority levels
    • SCHED_RR: This policy is very similar to SCHED_FIFO, but it uses a round-robin method to plan processes of the same priority. It also has at least 32 priority levels
    • SCHED_OTHER: It is a policy of planning defined by the implementation

    Services POSIX for process planning

    The three scheduling policies are defined in the header file

    Change the planning parameters of a process:

    Obtain the planning parameters of a process: