Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

INFORMATION SEARCH AND ANALYSIS SKILLS

(ISAS)
OPERATION SYSTEMS

“WINDOWS 10 I/O SYSTEMS”

Written by:

Rafif Nuraydin (2220010041)


Rayhan Alfarizi (2220010043)
Rivan Anjung Sinar Permana (2220010045)

Faculty:
Mrs. Aisah Rini Susanti, S.T., M. Kom.

Class:
1CC1

CEP-CCIT - Fakultas Teknik Universitas Indonesia, Gedung Engineering Center Lt. 1,


Kampus Baru UI Depok 16424
PREFACE

Thank you, the writer wishes to Allah SWT, the Almighty God for His blessings and mercy,
that we can complete this ISAS task, both in the form of paper and in the form of presentations in a
timely manner. Thank you especially for our faculty, Ivan Firdaus S.T who always help. Thank you
to the fellow students who have supported, and also thank you for being a partner in this education
at CCIT-FTUI.

The ISAS Paper entitled “Thread on Linux OS” which the authors propose as ISAS's 2020
task requirements.

Hope the author, hopefully this paper can be useful for the reader, so that it can add
knowledge and insight. The author realizes that this paper is not perfect. Therefore, the authors
really expect all constructive suggestions and criticisms from the reader to improve this paper.
Finally, hopefully this paper can provide many benefits for the readers.

Depok, 27 November 2020

Author

i
TABLE OF CONTENTS
PREFACE................................................................................................................................................i
TABLE OF CONTENTS........................................................................................................................ii
CHAPTER I INTRODUCTION.............................................................................................................1
1.1 Background..............................................................................................................................1
1.2 Writing Objective.....................................................................................................................1
1.3 Problem Domain.......................................................................................................................1
1.4 Writing Methodology...............................................................................................................1
1.5 Writing Framework..................................................................................................................2
CHAPTER II BASIC THEORY.............................................................................................................3
2.1 Thread.......................................................................................................................................3
2.2 Thread OS.................................................................................................................................3
2.2.1 Single Threading...............................................................................................................3
2.2.2 Multi Threading................................................................................................................4
2.3 Threading Model......................................................................................................................5
2.4 Multi Threading Model............................................................................................................5
2.4.1 Many to One.............................................................................................................................6
2.4.2 One to One................................................................................................................................6
2.4.3 Many to Many..........................................................................................................................7
2.5 Cancellation..............................................................................................................................7
2.6 Thread Pool..............................................................................................................................7
CHAPTER III PROBLEM ANALYSIS.................................................................................................9
3.1 Tread on Linux.........................................................................................................................9
3.2 Tread Creating..........................................................................................................................9
3.3 SMP (Symetric Multiprosesing).............................................................................................12
3.4 Kernel on Linux......................................................................................................................13
3.5 Examples Thread on Linux....................................................................................................13
CHAPTER IV CONCLUSION AND SUGGESTION.........................................................................15
4.1 CONCLUSION......................................................................................................................15
4.2 SUGGESTION.......................................................................................................................15
BIBLIOGRAPHY.................................................................................................................................16
APPENDIX of IMAGE........................................................................................................................17
APPENDIX of TABLE.........................................................................................................................17

ii
CHAPTER I
INTRODUCTION

1.1 Background
Due to technological developments in the field of operating systems, many companies are also
competing in creating operating systems with various feature innovations. One of them is the open
source Linux OS. Linux is an operating system based on free software and open source that uses the
Linux kernel. Typically, Linux is packaged in a form known as a Linux distro (distribution) for
desktop (PC) and server use. The main component of a Linux distribution is the Linux kernel, an
operating system kernel first released on 17 September 1991, by Linus Torvalds.

The operating system is a program that monitors and regulates the use of computer resources and
bridges the user / user with computer hardware, which in the operating system has many components
that play a role in it. One of the components in it is process and thread (Irfan, 2015[1]).

This is the background of the making of this paper, namely to explore the content contained in the
process and thread. With the aim that students can more or less understand what is a process and what
is a thread on a Linux OS.

1.2 Writing Objective


The purpose of writing this paper is to provide information and description about thread
completely and detail on Linux OS. Besides the writer want to explain How to how to create or test a
thread, and also the examples thread on Linux, and also.

1.3 Problem Domain


This ISAS will only discuss about thread especially thread on Linux OS which includes the
understanding, characteristics, and how to create or test a thread, and also the examples thread on
Linux.

1.4Writing Methodology
The writing method that applied by author is quite simple that the way is. Research, discuss and
analyze all of the information materials. Search all of the information from official and reliable
sources.

1
1.5 Writing Framework
To be more focused, then the discussion will be organized with a systematics writing as below:

 Chapter I Introduction

This chapter describes the background of the problem, the problem boundary, the purpose of the
writing, the writing methodology used, and the systematic writing of the paper.

 Chapter II Basic Theory

This chapter describes what thread is, what thread OS is, what threading model and multi-
threading model is, what cancellation is, and what thread pool is.

 Chapter III Problem Analysis

This chapter has more in depth discussion of what thread on Linux is, and how to create or test a
thread, and also the examples thread on Linux.

 Chapter IV Conclusion And Suggestion

This chapter contains the conclusions of the authors based on the experience gained after doing
research and getting useful suggestions from various sources.

2
CHAPTER II
BASIC THEORY

2.1 Thread
Thread is a control flow of a process. Threads are divided into two types, namely Single Thread
and multithreaded. Judging from its utility, multithread is the most widely used thread these days. A
multithreaded process contains several different control flows with the same address space. The
advantages of multithreaded include increased user responsiveness, sharing of process resources,
economy, and the ability to take advantage of multiprocessor architectures. A user level thread is a
thread that is visible to the programmer and is not recognized by the kernel. User thread levels are
typically managed by a library of threads in the user space. The thread level kernel is supported and
maintained by the operating system kernel. In general, user-level threads are faster to create and
maintain than kernel threads. There are three different types of models related to user and kernel
threads.

2.2 Thread OS
A thread in an operating system can be interpreted as a set of commands (instructions) that can
be executed parallel to other threads, using the method time slice (when one CPU performs a transfer
from one thread to another) or Multi process (when the threads are executed by different CPUs in one
system).

Threads are actually similar to processes, but the way of sharing resources between processes
with threads is very different. Multiple thread can be implemented parallel to the computer system.
Generally multithreading to do time-slicing (together with time-division multiplex), where a CPU is
working on different threads, where a case is handled not completely synchronously, for a single CPU
basically actually doing a job at one time.

Threads share parts of programs, parts of data and operating system resources with other
threads that refer to the same process. A thread consists of! "Threads, program counters, register set,
and stack." Its multiple control process threads can do more than one job at the same time.

2.2.1 Single Threading


A traditional process or heavyweight process has single thread which functions as a
controller. "Can be defined as a process that works sequentially according to their respective
sequence thread (structured) and only do one task at a time. Below is a picture of single thread.

3
Figure 2.1 Single Thread

2.2.2 Multi Threading


Represents one or several thread that run concurrently (multi process), where
respectively thread are executed on their respective lines. Every thread on multithreaded run
code or script programs sequentially. Multithread can also be interpreted as a process with
thread many can do more than one task at a time. Multithread often referred to as multi process
or multitasking on the system, below is a picture of multithreading.

Figure 2.2 Multi Thread

 Advantage
1. Responsive Multi-Threading allows a program to run continuously even
if that part of the program is blocked or is in a state of running long /
long operations. For example, a multithreaded web browser can allow
users to interact with a thread while an image is being loaded by another
thread.
2. Resource sharing by default, threads share memory and resources of
processes. When threads run on the same data, they can share cache

4
memory.
3. Economical Allocating memory and resources to create processes is very
expensive. Alternatively, because threads share the resources of the
process, it is more economical to create thread.
4. Multiprocessor architecture empowerment the advantages of multi-
threading can be enhanced with a multiprocessor architecture, where
each thread can run in parallel on different processors. In single-
processor architectures, the CPU usually switches between threads
quickly, giving the illusion of parallelism, but in reality only one thread
is running at a time.
 Disadvantage
1. Multiple threads can interfere with each other when sharing hardware
resources, for example cache memory.
2. The execution time of a single thread cannot be improved, but can be
decreased. This occurs because of a decrease in the frequency required
when there is a change in threads that are running.
3. There must be support from hardware or software for multi-threading.

2.3 Threading Model


Terminology of threading is divided into namely:
 User-level Threading
User threads are supported on top of the kernel and are implemented by the library thread
on user labels. The library provides facilities for thread creation, thread scheduling, and
thread management without support from the kernel. As for the weakness that is
experienced, that is if the kernel is a single thread then if one user-label thread runs a block
system call it will result in the entire process being blocked even though there are other
threads that can path in the application.

 Kernel-level Threading
Kernel threads are supported directly by the operating system. The creation, scheduling, and
management of threads are carried out by the kernel in the kernel space. The creation and
management of kernel threads is slower than user threads. The advantage is that if a thread runs
a blocking system call, the kernel can schedule other threads in the application to execute. In a
multiprocessor environment, the kernel can schedule threads on different processors, Examples
of operating systems that support kernel threads are:
1. windows NT
2. Solaris
3. Digital Unix

2.4 Multi Threading Model


Many operating systems support kernel thread and user thread in a combined way. Example of
such system is Solaris. Multithreading model are of three types, it is Many to One, One to One,
5
Many to Many.

2.4.1 Many to One


This model maps several thread levels user to a thread kernel level. Settings thread done
in space user so efficient. Only one user thread who can access thread kernel at a
moment. So Multiple threads cannot run in parallel on multiprocessors. Example from
many to one is Solaris Green Threads and GNU Portable Threads. Model Many to One
shown in the image below.

Figure 2.3 Many to One

2.4.2 One to One


This model maps each user level thread to each thread. One to One provide more
concurrency compared to the Many to One model. The advantages are the same as the
kernel threads. The weakness of this model is that each user thread creation requires an
additional thread the kernel. Therefore, if you implement this system it will reduce the
performance of an application so that it is usually the number thread restricted in the
system. There are also examples of one to one, namely Windows NT / XP 2000, Linux,
Solaris 9. Model One To One show in the image below.

Figure 2.4 One to One

6
2.4.3 Many to Many
This model multiplexes a lot thread levels user to thread the number of kernels that are
few or the same as levels user. this model wants developer make thread as much as that
developer want but concurrency cannot be obtained for only one thread which can be
scheduled by the kernel at any given time. The advantage of this system is that the kernel
thread can run in parallel on the multiprocessor. Model Many to Many shown in the
image below.

Figure 2.5 Many to Many

2.5 Cancellation
Thread cancellation is the termination of a thread before its task is complete. For example, if
the Java program wants to turn off the Java Virtual Machine (JVM). Before the JVM is turned off, all
running threads must be stopped first. The thread to be terminated is usually called the target thread.
Termination of the target thread can occur in two different ways:

 Asynchronous cancellation: a thread immediately terminates the target thread.


 Defered cancellation : the target thread periodically checks if it should stop, this way
it allows the target thread to stop itself sequentially.

The alternative is to use deffered cancellation. The way deffered cancellation works is by using
a single thread which functions as an indication that the target thread is about to be terminated. But the
stop will only happen if the target thread checks whether it should stop or not. This allows the thread to
check whether it should stop at a time when it can safely be terminated. Thread refers to these as
cancellation points.

2.6 Thread Pool


On a multithreading web server there are two problems that arise: The size of the time it takes
to create a thread to serve the submitted request, especially the fact that the thread is discarded when it
immediately finishes its task. Creating an unlimited number of threads can reduce the performance of
the system. The solution is with the use of thread pools, the way this works is to create multiple
threads during the startup process and place them into pools, where they sit idly by and wait to work.

7
So when the server receives a request it will wake up the thread from the pool and if the thread is
available then the request will be served. When the thread has finished doing its job it returns to the
pool and waits for other work. If there are no available threads, additional thread pool requests remain
queued until thread pool threads become available.

8
CHAPTER III
PROBLEM ANALYSIS

3.1 Tread on Linux


When it was first developed, Linux was not supported with threading in its kernel, but it did
support processes as entities that could be scheduled via clone () system calls. Linux now Supports
duplicating processes using the clone () and fork () system calls. Clone () has similar Properties to fork
(), except in that it creates a copy of the called process where it creates a Separate process that shares
the address space with the called process. Sharing the address space of the parent process allows
cloned tasks to be similar to separate threads. This division of Address space is possible because
processes are represented in the Linux Kernel.

In the Linux Kernel each process is represented as a unique data structure. So, instead of
Creating a new one, the new data structure contains a pointer that points to where the data is Located.
So when fork () is called, a new process is created along with the duplication of all Contents in the
parent process data structure, but when clone () is called, it does not duplicate the Parent process but
creates a pointer to the parent process data structure which allows the child Process to share the
memory and resources of its parent process. The Linux Thread project uses these system calls to
simulate threads in user space. Unfortunately, this approach has several Drawbacks.

This approach to threads contrasts greatly with operating systems such as Microsoft Windows
or Sun Solaris, which have explicit kernel support for threads (and sometimes call threads lightweight
processes). The name "lightweight process" sums up the difference in philosophies between Linux and
other systems. To these other operating systems, threads are an abstraction to provide a lighter, quicker
execution unit than the heavy process. To Linux, threads are simply a manner of sharing resources
between processes (which are already quite lightweight). For example, assume the author have a
process that consists of four threads. On systems with explicit thread support, there might exist one
process descriptor that in turn points to the four different threads. The process descriptor describes the
shared resources, such as an address space or open files. The threads then describe the resources they
alone possess. Conversely, in Linux, there are simply four processes and thus four normal task_struct
structures. The four processes are set up to share certain resources.

3.2 Tread Creating


Threads are created like normal tasks, with the exception that the clone () system call is passed
flags corresponding to specific resources to be shared:

clone(CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND, 0);

9
The previous code results in behavior identical to a normal fork (), except that the address
space, file system resources, file descriptors, and signal handlers are shared. In other words, the new
task and its parent are what are popularly called threads.

In contrast, a normal fork () can be implemented as

clone(SIGCHLD, 0);

And vfork() is implemented as

clone(CLONE_VFORK | CLONE_VM | SIGCHLD, 0)

The flags provided to clone () help specify the behavior of the new process and detail what resources
the parent and child will share. Table III.1 list the clone flags, which are defined in <linux/sched.h>,
and their effect.

10
Flag Meaning

CLONE_FILES Parent and child share open files.

CLONE_FS Parent and child share file system information.

CLONE_IDLETASK Set PID to zero (used only by the idle tasks).

CLONE_NEWNS Create a new namespace for the child.

CLONE_PARENT Child is to have same parent as its parent.

CLONE_PTRACE Continue tracing child.

CLONE_SETTID Write the TID back to user-space.

CLONE_SETTLS Create a new TLS for the child.

CLONE_SIGHAND Parent and child share signal handlers and blocked signals.

CLONE_SYSVSEM Parent and child share System V SEM_UNDO semantics.

CLONE_THREAD Parent and child are in the same thread group.

CLONE_VFORK vfork() was used and the parent will sleep until the child wakes it.

CLONE_UNTRACED Do not let the tracing process force CLONE_PTRACE on the child.

CLONE_STOP Start process in the TASK_STOPPED state.

CLONE_SETTLS Create a new TLS (thread-local storage) for the child.

CLONE_CHILD_CLEARTID Clear the TID in the child.

CLONE_CHILD_SETTID Set the TID in the child.

CLONE_PARENT_SETTID Set the TID in the parent.

11
Flag Meaning

CLONE_VM Parent and child share address space.

Table III.1 List the clone flags

12
In order to enhance Linux Thread capabilities, kernel support and thread library rewrites are
required. Two competing projects answer this challenge. A team of developers from IBM Created
NGPT (Next Generation POSIX Threads). While Red Hat's developers created the NPTL (Native
POSIX Thread Library), Linux doesn't really differentiate between processes and Threads. In fact,
Linux uses the term task rather than process and thread when referring to Control flow settings in a
program. Process status on Linux:
 Runining
 Interruptable
 Uninterruptable
 Stopped
 Zombie

Figure III. 1 Process Model on Linux

3.3 SMP (Symetric Multiprosesing)


Symmetric multiprocessing(SMP) involving multiprocessors computer hardware architecture in which
two or more identical processors are connected to one main shared memory and controlled by a single
OS instance Most common multiprocessor systems today use an SMP architecture Most common
multiprocessor systems today use SMP architectures In the case of multi-core processors, the SMP.

The SMP architecture applies to the cores, treating them as separate processors. In the case of multi-
core processors, SMP architecture applies to cores, treating them as separate processors. Processors
may be interconnected using buses, crossbar switches on-chip mesh networks. Processors may
interconnect using buses, crossbar switches or on-chip mesh networks.

13
3.4 Kernel on Linux
The kernel is a system from Linux, which controls the hardware and forms various low-level
functions, the functions carried out by the kernel, including: single service (system calls) and system
clock, file management and security management, input and output operation services, process
management and scheduling, memory management, performing system accounting activities, handling
interruption errors.

Figure III.2 Process on Kernel

3.5 Examples Thread on Linux

Following brief steps to create a simple thread on linux:

1.) Make sure that the include and id of the thread are included in the code
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
pthread_t tid[2];
Note pthread_tid is to create a thread id
2.) Create a thread at the core of the program (int main) using the pthread_create function
pthread_create (& (tid [i]), NULL, & doSomeThing, NULL);
Note:
● tid [i] is the thread id created in step 1
● do Some Thing is a function executed by a thread
3.) Make sure the thread has a function that is performed
14
void* doSomeThing(void *arg) {
unsigned long i = 0;
pthread_t id = pthread_self();

if(pthread_equal(id,tid[0])) {
printf("\n First thread processing\n");
}
else {
printf("\n Second thread processing\n");
}

for(i=0; i<(0xFFFFFFFF);i++);

return NULL;
}
Note: this function corresponds to step 2. This function is passed to pthread_create
4) If you want between threads to know each other (one thread knows there is another thread, so that
the process does not get an error) use the pthread_join function
pthread_join(th1, NULL);
pthread_join(th2, NULL);
Note: For example, if there are two threads named th1 and th2 that will be joined.

15
CHAPTER IV
CONCLUSION AND SUGGESTION

4.1 CONCLUSION
Thread is a control flow of a process. Threads are divided into two types, namely Single
Thread and multithread. Judging from its usefulness, multithread is the most widely used
thread lately. A multithreaded process contains several different control flows with the same
address space. The advantages of multithreaded include increased user responsiveness,
sharing of process resources, economics, and the ability to take advantage of multiprocessor
architectures User-level threads are threads that are visible to the programmer and are not
recognized by the kernel. User-level threads are typically managed. By the operating system
kernel, in general, thread-level users are faster to create and maintain than kernel threads.
There are three different types of models related to user and kernel threads.

 Many to one model: maps multiple user level threads to only one kernel thread

 One to one model: maps each user thread to one kernel thread, ending

 Many to many model: allows development to create as many user threads as possible,
concurrency cannot be achieved because only one thread can be scheduled by the
kernel at a time

When it was first developed, Linux was not supported with threading in its kernel, but it did
support processes as entities that could be scheduled via clone () system calls. Linux now
Supports duplicating processes using the clone () and fork () system calls. Then there is
Symmetric multiprocessing which involves a multiprocessor computer hardware architecture
where two or more identical processors are connected to one shared main memory and
controlled by a single OS. and the linux kernel, The kernel is a system from Linux, which
controls hardware and forms a variety of low-level functions, the functions performed by the
kernel include: single service (system calls) and system clock, file management and security
management, etc.

4.2 SUGGESTION

For user level threads


It is hoped that more threads in the Linux operating system will take advantage of the
multiprocessor, and do not require non blocking system calls

And then for kernel level thread


And the authors also suggest that the Linux Operating System should provide more features, so
that users can have a lot of content to choose from and security must be improved so that users
can feel comfortable using this OS.

16
BIBLIOGRAPHY

Irfan, 2015. SISTEM OPERASI PROSES DAN THREAD. Faculty of Informatics


[1]

Engineering, Dayanu Ikhsanudin University, Bau Bau, South East Sulawesi. [29/11/2020]

Atanasarah, 2011. SISTEM OPERASI THREAD DAN MULTITHREADING, Computers


[2]

and Information Systems, Vocational School, Gadjah Mada University, Yogyakarta.


[27/11/2020]

https://www.academia.edu/30582405/
[3]

MAKALAH_SISTEM_OPERASI_THREAD_Pengertian_Thread [27/11/2020]

https://vivimargaretha494.wordpress.com/2015/10/01/thread-pada-sistem-operasi-2/
[4]

[27/11/2020]

http://lutfiprod.blogspot.com/2017/10/contoh-thread-pada-os-linux.html [28/11/2020]
[5]

https://studylibid.com/doc/723204/perbedaan-threads--smp--kernel-di-windows-dan-linux
[6]

[28/11/2020]

17
APPENDIX of IMAGE

Figure II.1 Single Thread.....................................................................................................................4


Figure II.2 Multi Thread.......................................................................................................................4
Figure II.3 Many to One.......................................................................................................................6
Figure II.4 One to One..........................................................................................................................6
Figure II.5 Many to Many.....................................................................................................................7
Figure III.1 Process Model on Linux..................................................................................................12
Figure III.2 Process on Kernel...........................................................................................................13

APPENDIX of TABLE
Table III.1 List the clone flags...........................................................................................................11

18

You might also like