You are on page 1of 6

Name: John Patrick M.

Esmeria Section: BSCPE-301

Professor: Sir Cosme Mateo Date: October 17, 2022

Instructions:

1. Search for relative studies and/or literature regarding the process and thread concepts of the
following operating systems:

A. Linux OS

Linux has evolved a lot since its inception. It has become the most widely used operating system
when it comes to servers and mission critical work. Though it is not easy to understand Linux as
a whole, there are aspects which are fundamental to Linux and worth understanding.

Processes are fundamental to Linux as each and every work done by the OS is done in terms of
and by the processes. Just think of anything and you will see that it is a process. This is because
any work that is intended to be done requires system resources (that are provided by kernel) and
it is a process that is viewed by kernel as an entity to which it can provide system resources.
Processes have priority based on which kernel context switches them. A process can be pre-
empted if a process with higher priority is ready to be executed.

For example, if a process is waiting for a system resource like some text from text file kept on
disk then kernel can schedule a higher priority process and get back to the waiting process when
data is available. This keeps the ball rolling for an operating system as a whole and gives user a
feeling that tasks are being run in parallel. Processes can talk to other processes using Inter
process communication methods and can share data using techniques like shared memory.

Threads in Linux are nothing but a flow of execution of the process. A process containing
multiple execution flows is known as multi-threaded process. For a non-multi-threaded process
there is only execution flow that is the main execution flow and hence it is also known as single
threaded process. For Linux kernel, there is no concept of thread. Each thread is viewed by
kernel as a separate process but these processes are somewhat different from other normal
processes.

B. Android OS

When an application component starts and the application does not have any other components
running, the Android system starts a new Linux process for the application with a single thread
of execution. By default, all components of the same application run in the same process and
thread (called the "main" thread). If an application component starts and there already exists a
process for that application (because another component from the application exists), then the
component is started within that process and uses the same thread of execution. However, you
can arrange for different components in your application to run in separate processes, and you
can create additional threads for any process.

By default, all components of the same application run in the same process and most applications
should not change this. However, if you find that you need to control which process a certain
component belongs to, you can do so in the manifest file.

Android might decide to shut down a process at some point, when memory is low and required
by other processes that are more immediately serving the user. Application components running
in the process that's killed are consequently destroyed. A process is started again for those
components when there's again work for them to do.

When deciding which processes to kill, the Android system weighs their relative importance to
the user. For example, it more readily shuts down a process hosting activities that are no longer
visible on screen, compared to a process hosting visible activities. The decision whether to
terminate a process, therefore, depends on the state of the components running in that process.

When an application is launched, the system creates a thread of execution for the application,
called "main". This thread is very important because it is in charge of dispatching events to the
appropriate user interface widgets, including drawing events. It is also the thread in which your
application interacts with components from the Android UI toolkit (components from the
android.widget and android.view packages). As such, the main thread is also sometimes called
the UI thread.

The system does not create a separate thread for each instance of a component. All components
that run in the same process are instantiated in the UI thread, and system calls to each component
are dispatched from that thread. Consequently, methods that respond to system callbacks (such
as onKeyDown() to report user actions or a lifecycle callback method) always run in the UI
thread of the process.

For instance, when the user touches a button on the screen, your app's UI thread dispatches the
touch event to the widget, which in turn sets its pressed state and posts an invalidate request to
the event queue. The UI thread does not queue the request and notifies the widget that it should
redraw itself.

2. Then, provide or answer for the following for each operating system (Linux and Android):

 Provide a diagram showing the process and thread construct of the operating system. (5
points)

LINUX OS
ANDROID OS

 Briefly explain the diagram that you have provided. (5 points)

LINUX OS

A process in Linux is a single program running in its own virtual space on the operating system.
To create a process in Linux, the "parent process" initiate a fork(). Fork() suggests that the
process creates a copy of itself. A process in Linux is represented by a data structure is called
task-struct. It contains the all information about the process.

ANDROID OS

When an application is launched, the system creates a thread of execution for the application,
called "main". This thread is very important because it is in charge of dispatching events and
rendering the user interface and is usually called the UI thread. All components and their
executed code run in the same process and are instantiated by default in the UI thread.
Performing lengthy operations such as network access or database queries in the UI thread will
block the entire app UI from responding. When the UI thread is blocked, no events can be
dispatched, including drawing events. From the user's perspective, the application will appear to
freeze. Additionally, the Android UI toolkit is not thread-safe and as such you must not
manipulate your UI from a background thread.

 How does the operating system support or implement multithreading? (5 points)

LINUX OS

Linux has a unique implementation of threads. To the Linux kernel, there is no concept of a
thread. Linux implements all threads as standard processes. The Linux kernel does not provide
any special scheduling semantics or data structures to represent threads. Instead, a thread is
merely a process that shares certain resources with other processes. Each thread has a unique
task_struct and appears to the kernel as a normal process, which just happens to share resources,
such as an address space, with other processes.

ANDROID OS

Android can utilize multiple CPU cores for multithreading but the kernel and JVM handle that
process, not the developer himself. An internal multithreading design will improve the program's
basic performance, but the device upon which it actually runs will determine its speed.

 Is it possible to increase the number of threads within processes without affecting the
average response time of this operating system? Why or why not? (5 points)

LINUX OS

For optimal performance, Linux has a limit on the number of threads. The threads-max kernel
parameter can be set to ensure that the number of threads per process is always less than or equal
to that limit. However, other factors like the amount of virtual memory and stack size may
indirectly govern the number of threads allocated to a process. Linux has a setting for maximum
threads per process, which specifies the maximum number of simultaneous executions that the
process can handle. Changes to this can throttle the process and minimize latencies for the
executions that happen. Reaching this limit means the process needs many threads at peak load.
As long as it can serve requests in a timely manner, the process is adequately tuned. However,
when the limit is reached, threads queue up, potentially overloading the process. At this point,
the process defers creating new threads until the number of active threads drops below the limit.

ANDROID OS

Technically, there is no limit but at some point, having more threads is going to be less efficient
than having less. When an application is launched in Android, it creates the first thread of
execution, known as the “main” thread. The main thread is responsible for dispatching events to
the appropriate user interface widgets as well as communicating with components from the
Android UI toolkit. To keep your application responsive, it is essential to avoid using the main
thread to perform any operation that may end up keeping it blocked. Network operations and
database calls, as well as loading of certain components, are common examples of operations
that one should avoid in the main thread. When they are called in the main thread, they are called
synchronously, which means that the UI will remain completely unresponsive until the operation
completes. For this reason, they are usually performed in separate threads, which thereby avoids
blocking the UI while they are being performed (i.e., they are performed asynchronously from
the UI).

 What are the possible effects of multithreading in the central processing unit (CPU)
utilization of this operating system? Rationalize your answers. (5 points)

LINUX OS

Multithreading adds stability to the programs and prevent it from crashing. All threads run
independently. If an error is encountered by a thread, it should not affect rest of the program. It
allows better utilization of the processor and other system resources.

ANDROID OS

Developers multithread Android applications in order to improve their performance and


usability. By spinning off processor- or resource-intensive tasks into their own threads, the rest
of the program can continue to operate while these processor intensive tasks finish working. This
can include separating the thread for the graphical user interface from the threads that fetch
network data. The JVM automatically manages these multiple tasks, so Android developers do
not have to concern themselves with optimizing thread performance for a particular set of
hardware.

 Properly cite all your references (i.e., books, articles, dissertations, websites, etc.). (5
points)

Managing Threads and Custom Services. (n.d.). CodePath.


https://guides.codepath.com/android/managing-threads-and-custom-services#understanding-the-
main-thread
Linux Process and Thread Management. (n.d.). Webeduclick.com.
https://webeduclick.com/linux-process-and-thread-management/

Goshen, E. (2017, March 10). Android Threading: All You Need To Know. Toptal.
https://www.toptal.com/android/android-threading-all-you-need-to-know

Multithreading Essay. (n.d.). 123 Help Me. https://www.123helpme.com/essay/Multithreading-


Essay-445378

Processes and Threads Overview. (2021, October 27). Android Developers.


https://developer.android.com/guide/components/processes-and-threads

Arora, H. (2013, November 14). What are Linux Processes, Threads, Light Weight Processes,
and Process State. The Geek Stuff. https://www.thegeekstuff.com/2013/11/linux-process-and-
threads/

Linux Kernel Process Management. (2005, April 15). InformIT.


https://www.informit.com/articles/article.aspx?p=370047&seqNum=3#

Network Operating Systems Vs. Embedded Operating Systems. (2021, September 14). Chron.
https://smallbusiness.chron.com/network-operating-systems-vs-embedded-operating-systems-
46508.html

Maximum Number of Threads per Process in Linux. (2022, January 2). Baeldung.
https://www.baeldung.com/linux/max-threads-per-
process#:~:text=Thus%2C%20the%20number%20of%20threads,the%20total%20number%20of
%20threads

You might also like