# data[].attributes.body
Personal Reflection:
Actually i felt comfortable to write all of the notes in Onenote, cause i like my note with my hand writing. But OneNote doesn't provide link to share with my lecture. So i've decide to use padlet instead

important notes for Part 2 (OS Structures)
•system call is also an interrupt (A type of interrupt too)

Direct memory access structure:
let say typing a paragraph, event:
•Instead of transferring each character they lump up let say 20 characters, then only it moves into the memory
•By using this structure, less interrupt occurs, and lessen the time for CPU to do the transition
The situation explain the Direct Access Structure, which is:
-Interrupt-driven I/O can move small amount of data but can produce high overhead when used for bulk data. Therefore this structure combine all of the data into big chunk of data, and moves them into the memory(therefore minimizing the interrupt occurs & minimize CPU idle time)

MultiCore System:
what does it mean by having multicore processor?
=on one single CPU design, it has multiple processor, so the number of processor is what we call today quadcore, dualcore, tripelcore and so on..
= in other word, on on unit processor, it has multiple processor chips, therefore if a CPU has four processors, a single job will divide the job among this four processors. It is OS job to divide the task(a job) among these four processors

# data[].attributes.body
Personal Reflection:
I'm gonna used this note to prepare for examination anyway. So my note may contain a lot of content, but i write all of the things that i need to remember rather that make it short. I'll dump everything so that i don't need to go through the lect slide next time.

objectives:
•Identify services provided by an OS
•Illustrate how system calls are used to provide OS services

There are 2 types of OS services:
•For User
•For System Programs(e.i power point etc)

OS it provides services for both User and System Programs

for the user side, the services that being provided is:
1. User Interface(UI)- providing GUI, CLI, touch screen, Batch

2. Program Execution-  Helps program to load into the memory and run the program, end the execution , either normally or abnormally (indicate error)

3. I/O operations- A running program may require I/O, which may involve a file or an I/O device

4.File-system manipulation- The file that user may want to work with, the OS helps to read, write, create, delete, search, list file information and permission management

5. Communications- Processes may exchange information, on the same computer or between computer over a network

6. Error Detection- possible errors may occur and OS must be constantly aware if this happened
This event may occur on the CPU or memory hardware or I/O devices. The OS must know appropriate action needs to be taken

other than that OS helps to ensure efficient operation within the system itself via resource sharing

1. Resource allocation- If there are multiple users or jobs running at the same time, OS must allocate resources for each one of them

2. Logging- Keep track of which user and how much and what kinds of computer resources

3. Protection security- The owner's information may stored in multi users or networked computer system may want to control use of that information, concurrent process should not interfere with each other
• Protection ensure all access to system resource is controlled
• Security of the system from the outsiders requires user authentication,          extends to defending external I/O devices from invalid access attempts

System Calls
•Programming interface to the services that provided by the OS. And typically written in high-level language. And mostly accessed by programs via a high-level Application Program Interface(API)

•This means, we have multiple platforms and API acts as an intermediary between system calls and OS

•Its basically a piece of software that gives instruction on how to provide a service

Types System Calls
•Process control
•File management
•Device management
•Information maintenance
•Communications
•Protection

System Services
Providing a convenient environment for program development and execution

• File Management
• Status Information
• File modification
•Programming-language support
•Programming loading and execution
•Communication
•Background Services
•Application Programs

# data[].attributes.body
Personal refelction:
A lot of things to remember, felt like studying history for SPM

Objectives in this chapter:
Process concept
Process Scheduling
Operations on Processes
Interprocess Communication
IPC in Shared-Memory Systems
IPC in Message-Passing System
Examples Of IPC System

Process concept:
•Program that need execution in the OS is known as process
or in other word, OS execute variety of programs that run as a process

which mean it's READY for execution or IN execution its known as process
•Process- a program in execution; a process must go through several steps  from the beginning of its creation until its termination (sequential fashion)

*Other word, PROCESS IS ANY PROGRAM THAT IS IN EXECUTION*

and this this process consists of multiple parts:
•Program code(code that we write) aka text section
•Current activity; program counter (for every line code that has created generate a program counter - just like a marking line ), process registers
•Stack; Temporary data store Function parameters, return addresses, local variables
•Data Section; contain global variable
•Heap containing memory dynamically allocated during run time (where the address of where our process resides in the memory, during the run time)

when we write a program, and save it - PROGRAM
but when we execute, compile and run the program - PROCESS

on top of the code that we write previously will have all of the Multiple Parts (Program Counter, Stack & Heap)

• Process in active entity, while Program is a passive entity which stored in a disk
•Program becomes process when executable file loaded into memory
•Execution may start via GUI mouse click, command line entry of its name, etc
•A program can be several Processes (May have different function, called another function, another program, another object, etc..)
• Or consider multiple users executing the same program

Process State
A process when its in an execution, it changes state
•New: The process is being created
•Running: Instructions are being executed
•Waiting: The process is waiting for some event to occur
•Ready: The process is waiting to be assigned to a processor
•Terminated: The process has finished execution

Why OS keep changes from one state to another is because
Admitted = send to the memory

Flow Summary :
New>Ready>Running (Then 3 Possibilities might occur)
•Running>Ready
•Running>Terminated
•Running>Waiting>Ready

*Only processes in the ready state will be executed

Process Block Control
For each of the process the OS will keep the information about the process and will be kept in the register that is known as register Process Control Block(aka Task Control Block)

What are the information that the register kept?:
•Process State - running,waiting, etc
•Program counter - location of instruction to next execution
•CPU registers - contents of all process-centric registers
•CPU scheduling information - priorities, scheduling queue pointers
•Memory-management information - memory allocated to process
•Accounting information - CPU used, clock time elapsed since start, time limits
•I/0 status information - I/O devices allocated to process, list of open files

Threads:
•Within a process it may create threads
•When we have a process, that process may create many other small processes which known as threads

Process Scheduling
•The process will in many state. But in one time it can be only,ONLY in one state
•Processes can be either in one of the state(New, Ready, Running, Waiting, Terminated)
•To move kan all of this state to one and another we will use Process Scheduler/Scheduling
•Process Scheduler will select among available processes for the next execution on CPU core
•Its actually another instruction in OS which select the process from ready state into running (Ready>Running)

For this scheduling purposes it maintains 2 queues:
•Ready Queues - set all of the processes residing in main memory, ready and waiting to execute(many processes)
•Waiting Queues - set of processes waiting for an event(exp: I/O) (many processes)

*State running, is residing in the CPU and only had one process
*Time sliced expired= Interrupt (Let say the process only has 1 sec to finished its task, it will go back to ready queue)
*Interrupt waiting queue = An interrupt cause by I/O, It will go to waiting state

Context Switch:
•Let say a process in running state, suddenly its being interrupted, the state will go back to ready, or waiting, or being terminated. The CPU will stop what ever its doing and must look after the interrupt. While the CPU entertain the interrupt, it must save the State of existing process and load the new saved state of process
•When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process via context switching

•Context switching become time overhead- during context switching CPU does not do execution therefore the state is idle
*The CPU does not do any useful work
=In conclusion Context Switching is a waste of CPU time (Time consuming)

Some system comes comes with the hardware that help to reduce context switching by having multiple set CPU registers

Operation of the processes:
what the OS can do to the process?
= Process Creation
= Process Termination

Process Creation

It has a process, from that process it can be divided to other processes and the processes can be divided to many more processes(Tree of processes)

Sometimes the sub processes create Threads, and the threads will be considered a a children processes.(The child can be a thread)

•Parent process create children processes, which in turn create another process, forming a tree of processes
•Process Identifier (pid) managed and identified process
•Process can perform Resource Sharing & Execution Option:
*Parent and child can share all of the resources. Children only share the sub set of parent resources . Or parent and child does not share any resource
*Parent and child can execute concurrently. And parent will wait until child terminated then only the main process is being terminated as well

For address space:
•Child may duplicate of parent (Child stay within the parents space)
•Child has a program loaded into it (we can just load program into child)

Process Termination:
Os also in charge in the termination of a process
•Process execute the last statement and asks the OS to delete it using the exit() system call

if parent wants to terminate but child still not terminate parent will wait (via wait()) until the child finished execution then only the main process considered as finished execution and being terminated and remove from the memory

Process' resources are deallocated by OS (memory,space, any i/o, that a process hold will be released by an OS by being terminate)

Parent may terminate the execution of child processes using abort() system call when:
•The child has exceeded allocated resources (lama sangat dalam execution, so parents boleh terminate)
•Task assigned is no longer required
•The parent is existing and the OS does not allow  a child to continues if its parent terminates
•Some situations required both parents and child to be terminated. If a process terminates, then all its children must also be terminated.(The termination is being initiated by the OS)- Cascading Termination

# data[].attributes.body
Interprocess Communication
As we know there are many processes in OS, therefore these processes can be independent or cooperating

the reason for cooperation is:
•Information sharing
•Computation speedup
•Modularity
•Convenience
*mostly because of data, sometimes other resources. These reasons is why they need to cooperate, which known interprocess communication(IPC)

interprocess communication(IPC) only occurs for cooperating process

There are 2 models of IPC(which depends on OS what type of model they use):
•Shared memory
•Message passing (both processes that are cooperating will pass the message using link trace?)

Independent process will not be affected by other process execution
Cooperating process they can affect or be effected by other processes

In Cooperating Process there is a problem known as Producer-Consumer Problem:

In this case producer process in an entity who 'give' information , while consumer process is 'receiving' the information
So for OS to maintain this environment, it implement 2 phase:
•Unbounded-buffer : the OS provide a 'place' (a buffer) which have no limit, the shared area has no limit of size ( The shared memory may expand )
•Bounded-buffer : the OS provide a shared area (buffer) which have certain amount of size, which has limit of size  (Cause producer-consumer problem cause of the shared space size)

IPC of Shared memory :
•An area of memory, shared among the processes that wish to communicate
•The OS will provide the shared memory space only but the communication is controlled by the user process
•The problem, is when many user wants to communicate it must have synchronization of their actions in those shared space

IPC of Message passing - 3 parts (direct.. synchronous..., buffer):
•Mechanism for processes to communicate and to synchronize their actions
•Message system - processes communication with each other without resorting  to shared variables (There is no shared space of memory)

The facility provide 2 operations:
•send(message)
•receive(message)
The message size is either fixed or variable( depends nak hantar message tu besar mana pun)

Let say processes P & Q wants to communicate they must:
•Establish a communication link between them
•Exchange messages via send/link

How this communication is being done? Its either physical or logical:

Physical, using:
•Shared memory
•Hardware bus
•Network

Logical (Logical link), using:
•Direct or indirect
•Synchronous or asynchronous
•Automatic or explicit buffering

Direct Communication:
Both process must know each other name explicitly
•send(P, message) - send a message to process P
•receive(Q, message) - receive a message from process Q

Properties of communication link
•Links are established automatically (this will be done OS)
•A link is associated with exactly one pair of communicating processes
•Between each pair there exits exactly one link
•The link may be unidirectional(P can sent to Q only), but mostly bi-directional (P sent link to Q, Q sent link to P)

Indirect Communication:
Messages are directed and received from mailboxes (aka ports)
•Each mailbox has a unique id
•Processes can communicate only if they share a mailbox

Properties of communication link
•Link must be established only if processes share a common mailbox
•A link may be associated with many processes
•Each pair of processes may share several communication links
•The link may be unidirectional or bi-directional

Operations:
•create new mailbox(port)
•send and receive messages through mailbox
•destroy a mailbox (when no processes use the mailbox anymore)

How it works? It will have a command:
send(A, message) - send a message to mailbox A
receive(A, message) - receive a message from mailbox A
*It will go to the mailbox only and not to the process. Not like direct communication, it will go directly to the process

Mailbox may need to share
•p1, p2 & p3 share mailbox A
•p1 sends; p2 & p3 receive
•Who gets the message?
=logically p2 & p3

For the solution from this situations
•Allow a link to be associated with at most two processes
•Allow only one processes at a time to execute a receive operation (maybe p2 copy the data first then p3 follows)
•Allow the system to select arbitrarily the receiver. Sender is notified who the receiver was

Synchronization
This scheme did message passing too,but either blocking & non-blocking

Blocking is considered as synchronous
•Blocking send - the sender is blocked until the message is received
•Blocking receive - the receiver is blocked until a message is received

Non-blocking is considered as asynchronous
•Non-Blocking send - the send the message and continue, don't have to make sure
•Non-Blocking receive - the receiver receives: a valid message or null message

If both send and receive are blocking, we have a rendezvous(unblock the processes)

Buffering
almost similar to shared message, but it use a queue of messages that attached to the link

3 ways are being implemented:
•Zero capacity - no messages are queued on a link.
Sender must wait for receiver(rendezvous), sender send, receiver received, terminate process

•Bounded capacity - finite length of n messages
Sender must wait if link full, sender send, leave, do other process, but has limit for buffering

•Unbounded capacity - infinite length
Sender never waits, size can keep on growing

# data[].attributes.body
Personal reflection:
after all this chapter, i think i don't want to be an OS developer. Tooooo many components that is tooooo complex to understand

must understand CPU algorithm to understand this chapter

Basic concepts:
•to run the various process in the CPU, OS use multi-programming scheme (To have maximum utilization of CPU)
•The basic of execution is a cycle- cycle of CPU & I/O Burst(CPU Burst- Doing CPU execution, I/O Burst - doing I/O execution,the process is waiting for the I/O )
*The basic is that it will do CPU Burst or I/O Burst or it will go back to the ready state

•The main concern in this chapter is CPU Burst, cause we want to schedule the CPU so that it fully utilized the CPU

*CPU Burst and I/O Burst relates closely to process state diagram, espacially the read to running state
ready queue have many process, on one in running state, so CPU can execute one process at one time

CPU Scheduling is done by scheduler and the task is:
CPU Scheduling is about how the OS instruct or select processes from the ready queue to running and be done by scheduler  (ready queue is in the ram)

Ready>Running = CPU Burst
Running>Waiting(waiting I/O Event) = I/O Burst

When was the CPU scheduler needed?
•running>waiting
•running>ready (interrupt)
•waiting>ready(complete I/O burst)
•terminates(required another process to be dispatch to the CPU)

In CPU Scheduling there is 2 terms need to be remember:
•nonpreemptive
•preemptive(A job is being executed, it will complete its execution then only it will terminate)
In preemptive it must consider:
•access shared data
•preemptive while in kernel mode
•interrupts accurring during crucial OS activities

Dispatcher:
Its a module gives control of the CPU to the process selected by the short term scheduler, which involve:
•Switching context
•Switching to user mode
•jumping to the proper location in the user program to restart that program

Dispatch latency - time it takes for the dispatcher to stop one process and start another running

Scheduling Criteria (The goal of CPU Scheduling)
It must be certain criteria while selecting the processes:
•CPU Utilization (max)-  keep the CPU as busy as possible
•Throughput (max)- So that the number of processes that complete their execution per time is high
•Turnaround time (min)- amount of time to execute a particular process is short
•Waiting time (min) amount of time a process has been waiting in ready queue minimum as possible
•Response time (min)-  amount of time it takes from when a request was submitted until the first response is produced, not output (when it first created until the time it being pick up for execution)

# data[].attributes.body
Personal reflection
Every OS chapter is soooooo harrrrddd for me. Sometimes i understand the chapter and then the next thing i will be confused with a lot of terms to remember. But i will try hard to absorb all of important concept.

The concept:
•There are many processes(threads) running concurrently or parallel and these threads share the same resource, data,file, etc.
Therefore its OS task to synchronize the sharing of these processes by many process or threads

•The OS continuously update various data structures to support multiple threads

•If there's no synchronization there is tendency -  A race condition exits when access to shared data in not controlled resulting in corrupt data value
•To avoid this thing happens, process synchronization is needed
•The mechanism it that the OS task to coordinate among cooperating processes(The processes that sharing the same data,file,resources).
•This can be done by locking and critical section problem

What is process synchronization actually??:
•to synchronize OS user the synchronization tools
•it is involves using tools that control access to shared data to avoid race conditions. These tools must be used carefully, s their incorrect use can result n poor system performance or deadlock.

What are the tools?:
•Peterson's solution
•Mutex
•Semaphore

Critical section problem
in Process there is a segment code called critical section problem(a segment to share resources like data, file & database)
This section consist of:
•Entry section : requesting entry into the critical section
•Critical section : a section where one process executed at one of the time
•Exit section : releasing shared resources
•Remainder section : the rest off code execution - for the process to complete its execution(the process is actually not finished execution yet, but need to released shared data)

Every process must have request  to enter its critical section

Solution to the critical section:
In order to achieve the good use of shard data or the critical section  it must fulfil all of these criteria:
•Mutual Exclusion-  If one process in executing, so other processes can't be in the critical section, only one process can be in the critical section
•Progress- if the shared data are no being used, then it(process in the critical section) must allow another process to enter critical section
•Bounded waiting- there is a limited time set for processes to enter the critical section

The Handling:
There are two approaches for handling critical section:
•Preemptive - allows preemption of process when running in the kernel mode
•Non-preemptive -  runs until exits kernel mode, blocks or voluntarily yields CPU (esp free race condition)

Peterson's solutions & Mutex lock
Its a synchronization tools to synchronize the process the processes to enter critical section(CS) and solve CS problem
This tools are variations of software algorithms

Peterson's solutions
Its a two-process solution- this algorithm applicable at two process at a time:
•int turn : indicates whose turn it is to enter critical section
•boolean flag: indicate if a process is ready to enter critical section. flag[i]= true, means that the process is ready

Mutex Lock
a process must acquire lock before entering critical section; the lock will be release once it enters the critical area. This implements:
•acquire() function to acquire the lock and
•release() function to release the lock

this Mutex lock has a boolean variable - which the value indicates if the lock is available or not.  Lock available - call to acquire() succeeds

A process will be blocked if its try to acquires unavailable lock until the lock is released

# data[].attributes.body
A state when every process in a set is waiting for an event that can be caused only by another process in the set. This can be describe using a graph aka Resource Allocation Graph

System model: just to represent how deadlock works in computer system.

The Characteristic
if all of this characteristic occurs then deadlock consider happen(mesti empat2 ni berlaku)
•Mutual Exclusion:
•Hold and wait
•No preemption
•Circular wait

how to handle deadlocks?
firstly we have to make sure that deadlock will happen by:
•prevention: make sure none of 4 characteristic occurs
•avoidance: more infos required by the OS so that it can determine whether the current request will cause deadlock or not

Deadlock Prevention: Mutual Exclusion
•Some process only hold sharable resources like read only file and cannot hold any other type of resources

Deadlock Prevention: Hold and wait
•The process can't hold some resources and then requesting for more resources
•Therefore the process must:
-acquire all resources before its runs
-when a process request for another resources. it must hold none of them

Deadlock Prevention: No preemption
A preempted state occurs when a process is holding some resources and requesting some others that are being held by other processes.
for this situation not to happen it must:
• the requesting processes must wait until the resource is being released. While its waiting, its resources may be preempted

Deadlock Prevention: Circular wait
We can interrupt the cycle of waiting by doing the following: We can order all resource categories to break the circle of waiting (e.g., tapes, printers).
•A process can only request resources of higher types than the ones it already has.

Deadlock Avoidance: Mutual Exclusion
•Each process delivers the maximum amount of each type of resource it requires.
•To avoid a system deadlock, algorithms relying on this data are available. This is how a state operates. Deadlock avoidance is the goal here.

Deadlock Avoidance: Hold and wait
•A state is safe if the system can allocate resources to each process (up to its maximum, of course) and prevent a deadlock (safe state).
•In other words, a condition is safe if it has a safe sequence. Otherwise, the current state of the system is dangerous

# data[].attributes.body
main memory is actually one of the resource. This chapter focus on how CPU manage main memory

In this case Memory management keeps track of every single memory location, regardless of whether it is assigned to a process or not. It determines how much RAM each process is entitled to. Decisions about the allocation of memory are made here. It keeps track of when memory is released or unallocated and changes the state accordingly.

Why we need memory management?
•This method aids in optimising the use of memory by putting programmes in memory in the most efficient manner possible.
•These processes are protected from one other by this method, thus they do not interfere with each other.
•It improves in the distribution of  space among several programme routines.

How the OS do so?
There are methods use by OS to perform this memory management:
•Paging
•Segmentation
•Partitioning allocation
•Fragmentation
•Swapping

Swapping
Swapping is the process of bringing in each process in the main memory, running it for a while, and then putting it back to the disk.

Contiguous Memory Allocation
in this type of memory allocation, there is single contiguous block of memory in each processes. Memory is partitioned into a number of fixed-size blocks. And exactly one process contain in each partition. When partition is free, from the input queue, a process is chosen and fed into it. This free block of memory also known as holes. To identify which hole is the best to assign, the set of holes is searched.

Memory Protection
Memory protection refers to the process of controlling memory access privileges on a computer. Its major goal is to prevent processes from accessing memory that has not been assigned to them.

Memory Allocation in OS
•First Fit Allocation: The first hole that is big enough is allocated to the program.
•Best Fit Allocation: The smallest hole that is big enough is allocated to the program.
•Worst Fit Allocation: The largest hole that is big enough is allocated to the program.

Fragmentation
When the majority of the free blocks in a dynamic memory allocation system are too small to satisfy any request, fragmentation develops. The inability to utilise the available memory is a common description.

Processes are loaded and unloaded from memory in this context. As a result, free holes exist to fulfil requests, but they are non-contiguous, i.e. memory is split into large numbers of small holes. This is known as External Fragmentation.

In addition, physical memory is sometimes divided into fixed-size blocks, and memory is allocated in block sizes. It's possible that the memory assigned to space is somewhat larger than the amount requested. Internal fragmentation is the discrepancy between allocated and necessary memory.

# data[].attributes.body
Large programmes can store themselves in the form of pages in virtual memory while they are being executed, and only the needed pages or sections of processes are loaded into main memory. This approach is beneficial because it provides a big virtual memory for user programmes when the physical memory is limited.

Virtual memory can be implement by using:
•Demand paging
•Demand Segmentation

Demand Paging
Demand paging works on the idea that when a process is switched in, its pages are not swapped in all at once. Alternatively, they are only used when the process requires them (On-demand).Only those pages are loaded at first that will be required by the procedure right away.

The page table marks pages that haven't been moved into memory as invalid. The rest of the table is empty when an entry is invalid.

Page Replacement
What happens, though, when a process wants additional pages and there isn't enough free RAM to accommodate them?

This step will be taken by the OS:
•Place the process in the wait queue until any other process has completed its execution, freeing up frames.
•However, to release frames, eliminate some other process entirely from the memory.
•or, find any pages that aren't being utilised at the moment and transfer them to the disc to free up frames. This is known as Page replacement, and it is the most often used strategy.

# data[].attributes.body
Appreciation post:

Dear Madam,
Thank you so much for everything you've taught me. Despite the fact that I am not one of the best students or most active in the class, I really appreciated the time that you spent teaching every chapter. Even for me, this subject is hard. 😢

With all respect, thank you for all the knowledge. May Madam always be in Allah's protection! Thank you very much!  ✨

Thank you very much!

Sincerely,
your student😇

File Structure:

Simple Record Structure with lines of fixed or variable lengths.

Complex Structures like formatted document or reloadable load files.

No Definite Structure like sequence of words and bytes etc.

Attributes of a File:

Name . It is the only information which is in human-readable form.

Identifier. The file is identified by a unique tag(number) within file system.

Type. It is needed for systems that support different types of files.

Location. Pointer to file location on device.

Size. The current size of the file.

Protection. This controls and assigns the power of reading, writing, executing.

Time, date, and user identification. This is the data for protection, security, and usage monitoring.

File Access Methods
•Sequential Access
•Direct Access
•Indexed Sequential Access

What is a Directory?

Name : The name visible to user.

Type : Type of the directory.

Location : Device and location on the device where the file header is located.

Size : Number of bytes/words/blocks in the file.

Position : Current next-read/next-write pointers.

Protection : Access control on read/write/execute/delete.

Usage : Time of creation, access, modification etc.

Mounting : When the root of one file system is "grafted" into the existing tree of another file system its called Mounting.