Uploaded by Werdah Hashmi

LINUX and Windows

advertisement
A DEEPER LOOK INTO LINUX AND
ITS COMPARISON TO WINDOWS
A beginner friendly guide
Problem Statement
The design of operating systems impacts the computing landscape in a variety of ways. It plays a pivotal
role in giving performance edge to machines, ensuring that all precious resources are utilized to the
optimum. Comprehensibly, operating system of a machine is of paramount importance when it comes
to acceptance and adoption of the machine by the masses at large and commercial enterprises in
particular. It also underpins the development of software for a myriad of applications. In this context, the
open-source operating systems like different flavors of Linux have completely transformed the software
development arena.
The design and development of all cutting-edge operating systems have foundations in the dynamic
notion of the process. This complex engineering problem explores various aspects of process
management of the most prevalent open-source operating system Linux.
Table of Contents
Operating Systems .....................................................................................................................................................1
Linux ...........................................................................................................................................................................1
LINUX Process States .................................................................................................................................................2
Microsoft Windows Process States ...........................................................................................................................3
Comparison of Linux and Microsoft Windows Process States .................................................................................4
Thread Synchronization .............................................................................................................................................5
Condition Variables ................................................................................................................................................5
Reader – Writer Locks ............................................................................................................................................6
Comparison Analysis ..............................................................................................................................................7
Linux System Security ................................................................................................................................................7
User Privilege Separation ......................................................................................................................................8
Secure Inter Process Communication....................................................................................................................8
Conclusion ..................................................................................................................................................................9
References ........................................................................................................................................................... 10
Operating Systems
Operating systems are the backbone of modern computer technology, serving as the crucial software
that manages and controls all hardware and software resources. They provide a vital interface between
users and computer systems, enabling efficient communication and coordination of tasks. From personal
computers to smartphones, tablets, servers, and even embedded devices like smart home appliances or
car control systems – operating systems are omnipresent in our daily lives.
These complex pieces of software facilitate various essential functions such as managing memory,
scheduling tasks, handling input/output operations, providing security measures, and allowing different
applications to run simultaneously. Without an operating system in place, computers would be nothing
more than inert machines with limited capabilities.
Linux
LINUX is an open-source operating system that has transformed the world of technology. Developed in
1991 by Linus Torvalds, LINUX has grown to become one of the most popular operating systems globally,
powering millions of devices including servers, smartphones, and even supercomputers. Known for its
stability, security, and flexibility, LINUX offers a unique set of advantages that have attracted a passionate
community of developers and users alike.
Unlike proprietary operating systems such as Windows or macOS, LINUX’s open-source model has
fostered constant innovation and improvement in the system's functionality.
1
LINUX Process States
The Linux operating system is known for its efficient and reliable performance, largely due to its unique
process management capabilities. The concept of process states plays a crucial role in understanding how
Linux manages resources and ensures smooth multitasking.
In the Linux operating system, processes undergo various states during their execution. These states
represent different stages in the life cycle of a process and provide valuable insights into its current state
and behavior. By understanding these process states, system administrators and developers can
effectively manage system resources and troubleshoot performance issues.
The Linux process states are defined as follows:
Running or Runnable State: Although the running and runnable states are distinct, they are collectively
grouped into a single state denoted by the “R”. When a process is created, it is put in the running
(executing) state or the runnable (ready) state. In the runnable state the process is in the run queue,
waiting for its turn to be executed. In the running state, the process takes up the CPU resources and is
being executed. The thread scheduling algorithm allots time slices to these processes to ensure fair
sharing of CPU resources between processes.
2
Uninterruptible Sleep (Deep Sleep State): It is a blocked state. Also referred to as the "D" state, this
state occurs when a process is awaiting an action or resource that may take a long time to finish. For
instance, a process enters the uninterruptible sleep state when it is waiting for data from a slow disk or
completing a system call. When in this state, the process cannot be easily interrupted by signals and
remains blocked until the requested event occurs, because it is waiting directly on hardware conditions.
Interruptible Sleep (Sleep State): The Interruptible Sleep state is another type of blocked state. Also
referred to as the “S” state, it is very similar to the Uninterruptible Sleep state with the only exception
that it can be ‘awakened’ with a signal. A process enters the Interruptible Sleep state when it is waiting
for an event, for example a user input, completion of an I/O operation, availability of a resource, or a
signal from another process.
Zombie State: It is denoted as “Z” state. A process becomes a zombie when it has finished running but
its parent process has not yet read its exit status. Although they are included in the process table, zombie
processes do not use any system resources. They are eliminated from the process table only when their
parent process reads their exit status.
Stopped State: If a process receives a signal to halt its execution, it may be stopped or suspended. The
process enters the stopped state and stays there until it is either terminated or receives a signal to
resume its execution. The "T" state denotes a stopped process. Sending the appropriate signal enables
the restart or termination of a stopped process.
Microsoft Windows Process States
Microsoft Windows process states refer to the different stages that a program or application goes
through during its execution on a Windows operating system. These states play a vital role in managing
system resources and ensuring smooth multitasking capabilities.
The Microsoft Windows process states are defined as follows:
New: It is the state where a new process has been created, but no system or CPU resources have been
allocated to it yet. Here, it exists only as an entry in the Microsoft Windows process table.
Ready: In the Ready State, the processes are waiting for their turn to be executed. The processes are in
a Ready Queue, being managed by the CPU scheduler, to be selected and allotted CPU resources.
Running: When a Ready process is allotted system resource, it transitions into the running state. It is
when the process is being actively executed on the CPU.
3
Blocked (Waiting): It is when the execution of a process is halted because it is waiting upon some event,
like an I/O operation, some user input, or an output from some other process. Once a process enters a
blocked state, it is not considered for execution until the event it is waiting on occurs.
Suspend: A process in the suspended state is temporarily halted and not allowed to execute. This may
occur due to manual suspension by a user or system administrator, or when the process is waiting for a
resource that is currently unavailable.
Terminated (Exit): When a process completes its execution or is explicitly terminated, it enters the
terminated state. In this state, the process's resources are released and it is eliminated from the process
table.
Comparison of Linux and Microsoft Windows Process States
While both the operating systems follow a similar pattern of process transition, there are some
differences that are quite visible.
In Linux, the Running/ Runnable State comprises of processes that are both ready to be executed and
are actively being executed in real time. This state abstracts the Ready and the Running states of the
Microsoft Windows OS. There is also no New state in the Linux OS, unlike the Windows OS.
The Blocked state of the Windows OS is sib divided into two different states in the Linux OS, i.e., the
Uninterruptible Sleep State and the Interruptible Sleep State. While in Windows, there is only one
blocked state, for both the software and hardware interrupts, in the Linux OS, they are defined
separately.
When a process completes its execution in the Linux OS, it either enters the Zombie or the Stopped
state, while in windows, it transitions into the Terminated state. When a process must be suspended for
some reason, the Linux OS uses the same Stopped state to represent that, while in windows, there is a
separate Suspend state for such processes.
These Linux capabilities provide better insights into the process’s wait conditions and allow for more
targeted troubleshooting and optimization. By abstracting these states into a single category, Linux
simplifies the understanding and management of processes, providing a more simplified view of their
execution status. This simplicity and transparency in Linux's process transition model contributes to
enhanced control and ease of management, allowing for better resource utilization and better
performance.
4
Thread Synchronization
All the threads of a process share the same address space and other resources. Consequently, any
modification made by one thread impacts the environment for other threads within the same process.
It becomes crucial to synchronize the activities of these threads to prevent interference and data
corruption. It ensures that there is a safe way for threads to interact safely with the shared resources.
For instance, if a thread adds to a stack while the other one tries to read from the stack, it will get
modified data, instead of the original data. Therefore, synchronization is necessary to ensure proper
coordination and prevent such issues.
Synchronization primitives are software and hardware solutions that are used to coordinate and control
the execution of parallel processes or threads to avoid interference and conflicts with shared resources.
The primary purpose of synchronization primitives is to establish mutual exclusion, coordination, and
communication between processes or threads to maintain data integrity and prevent race conditions.
They are used to ensure that critical sections of code or shared resources are accessed in a controlled
and orderly manner.
In Linux, there are multiple thread synchronization primitives:
1.
2.
3.
4.
5.
6.
Mutexes
Semaphores
Condition variables
Spinlocks
Barriers
Reader – Writer locks
Condition Variables
Condition variables are a synchronization mechanism that enables threads to efficiently wait for specific
conditions to be met before proceeding. They are often used in conjunction with mutexes to provide
controlled access to shared resources and facilitate inter-thread communication.
A condition variable consists of two main operations: wait and signal.
1. Wait Operation: When a thread encounters a condition variable's wait operation
(`pthread_cond_wait()` in Linux), it atomically releases the associated mutex and enters a
blocked state, waiting for a condition to occur. This allows other threads to proceed while the
waiting thread is paused. The wait operation also atomically unlocks the mutex, allowing other
threads to access the shared resource protected by the mutex.
5
2. Signal Operation: The signal operation (`pthread_cond_signal()`) is used by a thread to notify
one waiting thread associated with the condition variable that a condition has occurred. The
signaled thread is then awakened and can proceed with its execution. It's important to note that
signaling a condition does not transfer the ownership of the mutex. The signaled thread must
reacquire the mutex before accessing the shared resource.
The combination of condition variables and mutexes allows threads to safely wait for specific conditions
without resorting to busy-waiting or consuming excessive system resources. This efficient waiting and
signaling mechanism help achieve proper synchronization, prevents unnecessary resource contention,
and facilitates orderly execution in multi-threaded applications.
Reader – Writer Locks
Reader-Writer locks, also known as shared-exclusive locks, are a synchronization mechanism that allows
multiple threads to read a shared resource concurrently while ensuring exclusive access for writing.
Reader-Writer locks provide a balance between maximizing parallelism for read operations and ensuring
data consistency during write operations.
The main idea behind Reader-Writer locks is to prioritize concurrent read access while allowing only one
thread to hold the exclusive lock for writing. This is beneficial in scenarios where multiple threads need
to read shared data, but writes should be serialized to maintain data integrity.
In a Reader-Writer lock, threads can acquire one of two types of locks:
1. Read Lock: Multiple threads can acquire a read lock simultaneously, indicating their intention to read
the shared resource. The read lock allows concurrent access among readers, as read operations do not
modify the shared resource. Threads holding the read lock can proceed simultaneously without
interfering with each other.
2. Write Lock: Only one thread can acquire the write lock at a time, indicating exclusive access for writing
to the shared resource. The write lock ensures that no other thread, neither readers nor writers, can
access the resource during a write operation. This exclusive access guarantees data consistency and
prevents race conditions or conflicts.
6
Comparison Analysis
Reader-Writer locks and condition variables in Linux are both important synchronization mechanisms
used in multi-threaded environments, but they serve different purposes and offer distinct advantages.
Reader-Writer locks, also known as shared-exclusive locks, provide a mechanism for multiple threads to
access a shared resource concurrently while ensuring exclusive access for writing. They strike a balance
between maximizing parallelism for read operations and maintaining data consistency during write
operations. Reader-Writer locks are efficient in scenarios where read operations heavily outnumber
write operations, as they allow for high concurrency and parallelism among readers while ensuring data
integrity during writes.
On the other hand, condition variables are synchronization primitives used for inter-thread
communication and coordination. They enable threads to wait for specific conditions to be met before
proceeding. Threads synchronize their activities and avoid busy-waiting or unnecessary resource
consumption. Condition variables are effective when threads need to coordinate their execution based
on specific conditions, such as waiting for a shared resource to become available or a particular event to
occur.
In summary, Reader-Writer locks are suitable when multiple threads need concurrent read access while
ensuring exclusive access for writing. They prioritize parallelism for reading and data consistency for
writing. Condition variables, in contrast, facilitate inter-thread communication and coordination,
allowing threads to wait and wake up based on specific conditions. They are valuable for synchronization
when threads need to coordinate their activities and respond to particular events.
Linux System Security
Process management security is a crucial aspect of Linux operating systems, ensuring the protection and
stability of computer systems. With the rise of cyber threats and attacks, it has become increasingly
important to implement robust security measures in managing processes in Linux environments. From
process creation to termination, Linux provides various mechanisms to ensure that processes run
securely and do not pose a risk to system integrity.
Linux process management incorporates several features that contribute to system security. These
features help protect the system from unauthorized access, malicious activities, and potential
vulnerabilities. Here are some key features of Linux process management that substantiate system
security:
1. Process Isolation
7
2.
3.
4.
5.
6.
User Privilege Separation
Process Permission and Access Control
Process Monitoring and Auditing
Secure Process Communication
Rapid Patching and Security Updates
User Privilege Separation
User privilege separation in Linux refers to the practice of assigning different levels of privileges to users
or processes based on their roles and responsibilities. It aims to restrict the capabilities and actions that
a user or process can perform, thereby reducing the potential impact of compromised components and
protecting the overall system security.
User privilege separation involves the following key aspects:
1. User Accounts: Each user is assigned a unique account with its associated credentials (username and
password).
2. User Groups: Users can be organized into groups, allowing for efficient management of permissions
and access control.
3. Privilege Levels: Linux differentiates between privileged (root) and non-privileged (regular) users. The
root user has full administrative privileges. Regular users operate with limited privileges.
4. Privilege Escalation: Linux provides mechanisms for privilege escalation, allowing regular users to
temporarily obtain elevated privileges when necessary. The most common mechanism is the `sudo`
command. Privilege escalation requires authentication.
By enforcing user privilege separation, Linux ensures that processes and users operate with the least
privileges necessary for their tasks. This minimizes the risk of unauthorized access, limits the impact of
compromised processes, and mitigates the potential for accidental or malicious misuse of system
resources. User privilege separation is a fundamental security practice in Linux, enhancing system
security and protecting against unauthorized actions or data breaches.
Secure Inter Process Communication
Secure inter-process communication (IPC) in Linux refers to the practice of exchanging data between
processes while ensuring the confidentiality, integrity, and authenticity of the communicated
information. It involves implementing mechanisms and protocols that protect sensitive data from
unauthorized access, tampering, or interception during communication.
8
Linux offers several methods for secure IPC, including the following:
1. Encrypted Sockets: Linux supports the use of Transport Layer Security (TLS) or Secure Sockets Layer
(SSL) protocols to establish secure encrypted communication channels between processes.
2. Message Queues: Linux message queues facilitate secure communication between processes by
providing a controlled and authenticated channel for data exchange. Message queues can be configured
with appropriate permissions, ensuring that only authorized processes can access and exchange
messages.
3. Shared Memory with Access Controls: When processes share memory regions for communication,
Linux allows the use of access controls to ensure secure access and prevent unauthorized modification
or tampering of shared data. Proper permissions and access restrictions are enforced to protect the
integrity of shared memory.
Properly configuring permissions and access controls is crucial for securing IPC in Linux. By setting
appropriate permissions on IPC resources like sockets, shared memory, and message queues, Linux
ensures that only authorized processes can access or modify them. This, along with encryption, secure
protocols, and access controls, helps protect sensitive data and communications from unauthorized
access, tampering, and eavesdropping. Linux provides a strong framework for secure IPC, enhancing
system security and preserving the confidentiality and integrity of inter-process communication.
Conclusion
In conclusion, Linux processes and thread synchronization primitives play a vital role in the efficient and
secure operation of the operating system. Thread synchronization primitives enable effective
coordination and communication among concurrent threads, ensuring proper resource utilization and
preventing data corruption.
Moreover, Linux's emphasis on security is evident in its process management features. User privilege
separation, process isolation, and secure inter-process communication mechanisms contribute to robust
system security. By enforcing user privileges, limiting access, and providing secure communication
channels, Linux mitigates the risk of unauthorized access, data breaches, and malicious activities.
When compared to Windows, Linux stands out in terms of its transparent and open-source nature, which
enables continuous security improvements, rapid patching, and extensive community support. Linux's
modular architecture and customizable nature contribute to its resilience against security vulnerabilities.
9
While Windows also offers process management and thread synchronization mechanisms, Linux's
emphasis on security, open-source development, and fine-grained control over process behavior make
it a preferred choice for security-conscious environments.
References
https://www.baeldung.com/Linux/process-states
https://www.educative.io/answers/what-are-conditional-variables-in-os
https://linuxsecurity.com/features/how-secure-is-linux
https://www.linuxjournal.com/content/how-properly-manage-inter-process-communicationlinux#:~:text=Inter%2Dprocess%20communication%20(IPC),them%20using%20the%20IPCS%20comma
nd.
Operating Systems – Internals and Design Principles (9th edition) by William Stallings
10
Download