0% found this document useful (0 votes)
47 views8 pages

Operating System File 5 & 6

The document discusses file systems, including their purpose, components, and types. File systems organize files in a computer and include metadata for attributes, permissions, and locations. Major file system types include FAT, GFS, HFS, NTFS, and UDF.

Uploaded by

Prabhav Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views8 pages

Operating System File 5 & 6

The document discusses file systems, including their purpose, components, and types. File systems organize files in a computer and include metadata for attributes, permissions, and locations. Major file system types include FAT, GFS, HFS, NTFS, and UDF.

Uploaded by

Prabhav Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Program – 5

Program 5: Implement deadlock in C by using shared variable.

Deadlock in operating system is a situation which occurs when a process or


thread enters a waiting state because a resource requested is being held by
another waiting process, which in turn is waiting for another resource held by
another waiting process. In a deadlock state a process is unable to change its
state (waiting) indefinitely because the resources requested by it are being used
by another waiting process.

Setup

To simulate deadlock in the system we will create the above shownsituation.

P1 and P2 will be represented by two thread one and two.


The two resources R1 and R2 will be represented by the two lock variables
first_mutex and second_mutex
First thread one will acquire lock first_mutex and then thread two will acquire
lock second_mutex. Hence, both the threads have acquired one resource each.
Next, thread one will try to acquire
lock second_mutex while the second thread, thread two will try to acquire
lock first_mutex. Since the resources are already occupied by the other thread,
both the threads will get into a deadlock.
Program to create Deadlock Using C in Linux using Mutex Locks and
threads

#include<stdio.h>
#include<pthread.h>
#include<unistd.h>
void *function1(); void
*function2();
pthread_mutex_t first_mutex; //mutex lock
pthread_mutex_t second_mutex;
int main() {
pthread_mutex_init(&first_mutex,NULL); //initialize the lock
pthread_mutex_init(&second_mutex,NULL);
pthread_t one, two;
pthread_create(&one, NULL, function1, NULL); // create thread
pthread_create(&two, NULL, function2, NULL); pthread_join(one,
NULL);
pthread_join(two, NULL);
printf("Thread joined\n");
}

void *function1( ) {

pthread_mutex_lock(&first_mutex); // to acquire the resource/mutexlock

printf("Thread ONE acquired first_mutex\n");

sleep(1); pthread_mutex_lock(&second_mutex);

printf("Thread ONE acquired second_mutex\n");

pthread_mutex_unlock(&second_mutex); // to release the resource

printf("Thread ONE released second_mutex\n");

pthread_mutex_unlock(&first_mutex);

printf("Thread ONE released first_mutex\n");


}
void *function2( ) {
pthread_mutex_lock(&second_mutex);
printf("Thread TWO acquired second_mutex\n");
sleep(1);
pthread_mutex_lock(&first_mutex); printf("Thread
TWO acquired first_mutex\n");
pthread_mutex_unlock(&first_mutex);
printf("Thread TWO released first_mutex\n");
pthread_mutex_unlock(&second_mutex);
printf("Thread TWO released second_mutex\n");
}

Synchronization primitives Mutex locks • Used for exclusive access to a shared


resource (critical section) • Operations: Lock, unlock Sempahores •
Generalization of mutexes: Count number of available “resources” • Wait for
an available resource (decrement), notify availability (increment) • Example:
wait for free buffer space, signal more buffer space Condition variables •
Represent an arbitrary event • Operations: Wait for event, signal occurrence of
event • Tied to a mutex for mutual exclusion 5 Condition variables Goal: Wait
for a specific event to happen • Event depends on state shared with multiple
threads Solution: condition variables • “Names” an event • Internally, is a queue
of threads waiting for the event Basic operations • Wait for event • Signal
occurrence of event to one waiting thread • Signal occurrence of event to all
waiting threads Signaling, not mutual exclusion • Condition variable is
intimately tied to a mutex
Program – 6
Program 6: File system: Introduction to File system, File system
Architecture and FileTypes.

In a computer, a file system -- sometimes written filesystem -- is the way in


which files are named and where they are placed logically for storage and
retrieval. Without a file system, stored information wouldn't be isolated into
individual files and would be difficult to identify and retrieve. As data
capacities increase, the organization and accessibility of individual files are
becoming even more important in data storage.

Digital file systems and files are named for and modeled after paper- based
filing systems using the same logic-based method of storing and retrieving
documents.

File systems can differ between operating systems (OS), such as Microsoft
Windows, macOS and Linux-based systems. Some file systems are
designed for specific applications. Major types of file systems include
distributed file systems, disk-based file systems and special purpose file
systems.

How file systems work


A file system stores and organizes data and can be thought of as a type of index
for all the data contained in a storage device. These devices can include hard
drives, optical drives and flash drives.

File systems specify conventions for naming files, including the maximum
number of characters in a name, which characters can be used and, in some
systems, how long the file name suffix can be. In many file systems, file names
are not case sensitive.

Along with the file itself, file systems contain information such as the size of
the file, as well as its attributes, location and hierarchy in the directory in the
metadata. Metadata can also identify free blocks of available storage on the
drive and how much space is available.
Example of a file tree diagram

A file system also includes a format to specify the path to a file through the
structure of directories. A file is placed in a directory -- or a folder in Windows
OS -- or subdirectory at the desired place in the tree structure. PC and mobile
OSes have file systems in which files are placed somewhere in a hierarchical
tree structure.

Before files and directories are created on the storage medium, partitions should
be put into place. A partition is a region of the hard disk or other storage that the
OS manages separately. One file system is contained in the primary partition,
and some OSes allow for multiple partitions on one disk. In this situation, if one
file system gets corrupted, the data in a different partition will be safe.

File systems and the role of metadata


File systems use metadata to store and retrieve files. Examples of metadata tags
include:
• Date created

• Date modified
• Last date of access
• Last backup
• User ID of the file creator
• Access permissions
• File size

Metadata is stored separately from the contents of the file, with many file
systems storing the file names in separate directory entries. Some metadata may
be kept in the directory, whereas other metadata may be kept in a structure
called an inode.

In Unix-like operating systems, an inode can store metadata unrelated to the


content of the file itself. The inode indexes information by number, which can
be used to access the location of the file and then the file itself.

An example of a file system that capitalizes on metadata is OS X, the OS used


by Apple. It allows for a number of optimization features, including file names
that can stretch to 255 characters.

File system access


File systems can also restrict read and write access to a particular group of
users. Passwords are the easiest way to do this. Along with controlling who can
modify or read files, restricting access can ensure that data modification is
controlled and limited.

File permissions such as access or capability control lists can also be used to
moderate file system access. These types of mechanisms are useful to prevent
access by regular users, but not as effective against outside intruders.

Encrypting files can also prevent user access, but it is focused more on
protecting systems from outside attacks. An encryption key can be applied to
unencrypted text to encrypt it, or the key can be used to decrypt encrypted text.
Only users with the key can access the file. With encryption, the file system
does not need to know the encryption key to manage the data effectively.

Types of file systems


There are a number of types of file systems, all with different logical structures
and properties, such as speed and size. The type of file system can differ by OS
and the needs of that OS. The three most common PC operating systems are
Microsoft Windows, Mac OS X and Linux. Mobile OSes include Apple iOS
and Google Android.
Major file systems include the following:

File allocation table (FAT) is supported by the Microsoft Windows OS. FAT
is considered simple and reliable, and it is modeled after legacy file systems.
FAT was designed in 1977 for floppy disks, but was later adapted for hard
disks. While efficient and compatible with most current OSes, FAT cannot
match the performance and scalability of more modern file systems.

Global file system (GFS) is a file system for the Linux OS, and it is a shared
disk file system. GFS offers direct access to shared block storage and can be
used as a local file system.

GFS2 is an updated version with features not included in the original GFS, such
as an updated metadata system. Under the terms of the GNU General Public
License, both the GFS and GFS2 file systems are available as free software.

Hierarchical file system (HFS) was developed for use with Mac operating
systems. HFS can also be referred to as Mac OS Standard, and it was succeeded
by Mac OS Extended. Originally introduced in 1985 for floppy and hard disks,
HFS replaced the original Macintosh file system. It can also be used on CD-
ROMs.

The NT file system -- also known as the New Technology File System
(NTFS) -- is the default file system for Windows products from Windows NT
3.1 OS onward. Improvements from the previous FAT file system include better
metadata support, performance and use of disk space. NTFS is also supported in
the Linux OS through a free, open-source NTFS driver. Mac OSes have read-
only support for NTFS.

Universal Disk Format (UDF) is a vendor-neutral file system used on optical


media and DVDs. UDF replaces the ISO 9660 file system and is the official file
system for DVD video and audio as chosen by the DVD Forum.

File system vs. DBMS


Like a file system, a database management system (DBMS) efficiently stores
data that can be updated and retrieved. The two are not interchangeable,
however. While a file system stores unstructured, often unrelated files, a DBMS
is used to store and manage structured, related data.
A DBMS creates and defines the restraints for a database. A file system allows
access to single files at a time and addresses each file individually. Because of
this, functions such as redundancy are performed on an individual level, not by
the file system itself. This makes a file system a much less consistent form of
data storage than a DBMS, which maintains one repository of data that is
defined once.

The centralized structure of a DBMS allows for easier file sharing than a file
system and prevents anomalies that can occur when separate changes are made
to files in a file system.

There are methods to protect files in a file system, but for heavy-duty security, a
DBMS is the way to go. Security in a file system is determined by the OS, and
it can be difficult to maintain over time as files are accessed and authorization is
granted to users.

A DBMS keeps security constraints high, relying on password protection,


encryption and limited authorization. More security does result in more
obstacles when retrieving data, so in terms of general, simple-to-use file storage
and retrieval, a file system may be preferred.

File systems definition evolves


While previously referring to physical, paper files, the term file system was used
to refer to digital files as early as 1961. By 1964, it had entered general use to
refer to computerized file systems.

The term file system can also refer to the part of an OS or an add-on program
that supports a file system. Examples of such add-on file systems include the
Network File System (NFS) and the Andrew File System (AFS).

In addition, the term has evolved to refer to the hardware used for nonvolatile
storage, the software application that controls the hardware and architecture of
both hardware and software.

You might also like