Understanding Process Management in Open Source Operating Systems

Slide Note
Embed
Share

Explore the fundamentals of managing processes in open source operating systems, including process states, process relationships, process spawning, and the fork system call. Learn how processes are tracked, managed, and interact within the Linux environment.


Uploaded on Oct 01, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Open Source Operating System Lecture (7) Dr.Samah Dr.Samah Mohammed Mohammed

  2. Objectives Managing processes Process states fork system call exec system call Type of process management

  3. Managing Processes A process is a running program. Processes can be started from : (1)GUI (2)CLI (3) Processes can also start other processes. Whenever a process runs, Linux keeps track of it through a process ID (PID). After booting, the first process is an initialization process called init. It is given a PID of 1. Each new process gets the next available PID.

  4. It also maintains information as to the relationship between processes, if any (child / parent process) A parent process is simply a process that starts a new child process. A new or child process inherits the exported environment of its parent process A child process receives an exported copy of the parent s environment. Thus, any changes the child makes to its environment does not automatically affect the parent process Managing these processes is one of the most important tasks given any administrator.

  5. A process can exist in one of many states: Runable on run queue, in effect one of currently executing processes Sleeping waiting for event to occur to wake up and react/start up Stopped not currently executing, waiting to be killed or restarted Uninterruptable sleep cannot be woken until specific expected event Defunct (zombie) process just before a process dies, it notifies its parent and waits for an acknowledgment If it never receives it, its PID is not freed up but all other resources are freed. Zombies can usually be cleared by rebooting/restarting the system.

  6. Parent and Child Processes The parent process spawns (produce)one or more child processes. The spawning of a process can be accomplished in one of several ways: fork() vfork() clone() wait() exec()

  7. fork System Call The fork system call duplicates the parent to initialize the child. The child then obtains the same contents as is stored in memory for the parent including such values as the current working directory, the terminal window in which the parent (and child) was launched. The only difference between the two is the PIDs of the processes and the location in memory of the processes.

  8. vfork System Call The two processes (parent and child) actually share the same memory. clone System Call Similar to vfork, the two processes share memory, but also share other resources. Used to create threads. wait System Call Like fork except that the parent goes into a wait (sleep) mode until the child terminates and then , the parent can resume execution..

  9. exec System Call Causes a process to start a program which replaces the current process. So the process invoking exec will be replaced by the new running process. The new running process is given the parent process PID.

  10. Example (1) When terminal window opened (running a BASH), and the program vi invoked from this shell. The bash first issues a fork call to duplicate itself and then the child issues an exec to replace itself with the vi program.

  11. Forms of Process Management The program is a static entity because it is exists in one of two states source codeor the executable code. The process is an active entity. As the process executes, the data change; variables change values, program move between swap space and memory, move within memory, processor The operating system must keep track of the program s state using a data structure called the process status word (PSW).

  12. Forms of Process Management Cont.. The PSW will be a collection of the most important pieces of information about the running process. Aside from keeping track of a process status, the operating system is in charge of scheduling when processes run, and of changing the process status as needed. Handling the scheduling and movement of processes is called process management.

  13. + Processor Organization Processor Requirements: Fetch instruction The processor reads an instruction from memory (register, cache, main memory) Interpret instruction The instruction is decoded to determine what action is required Fetch data The execution of an instruction may require reading data from memory or an I/O module

  14. Instruction Cycle Includes the following stages: Fetch Execute Interrupt If interrupts are enabled and an interrupt has occurred, save the current process state and service the interrupt Read the next instruction from memory into the processor Interpret the opcode and perform the indicated operation

  15. Type of process management Single tasking Multiprogramming Multiprocessing Multithreading Batch

  16. Single Process Execution The computer is limited to running only the one process until either that process terminates or the user suspends that process. So suspending a process was only possible by terminating the process. The user must submit the input (data or file) with the job as well as the destination for the output.

  17. Single Process Execution Cont.. During execution of a process, if it needs to input from tape file, this will cause a pause in the execution because of the relative slowness of tape input. During this time, the CPU idles. The system receives user requests to run processes and schedules them using some type of scheduling algorithm (FIFO,priority scheme, shortest job first ) Whichever algorithm is applied for scheduling, it is the scheduler s task to order the jobs and place them in a queue(waiting line) reflecting the scheduled ordering.

  18. Multiprogramming Processing In multiprogramming, the CPU execute a single process, but if the process needs to perform time consuming I/O, that process is removed and moved by the operating system into an I/O queue and selects the next waiting process for execution by the CPU.

  19. Multiprocessing Processing When the computer has multiple processors. The process management used is multiprocessing The operating system selects the processor to run a given process so multiple processors can execute their own processes. Load balancing allows the operating system to move processes between processors if necessary. Linux by default uses cooperative and preemptive multitasking and multithreading.

  20. Starting, Pausing and Resuming Processes Ownership of Running Processes Many running processes require access to files (or other resources). Example:vi text editor must obtain access rights to open or save a file in home directory. When a process is launched by the user, the process takes on the user s UID and the user s group s GID. So the process has the same access rights that the user has.

  21. Special Software Accounts Some applications require access to their own file space and their own files; therefore these applications have a special account is created for it. Example: The lp command (print files) copies the output to a printer spool file /var/spool (not accessible to the user). lp has its own user account it has a home directory of /var/spool/lpd and a login shell of /sbin/nologin (no login shell because we will not log in using lp account). When running lp, the operating system switches from you the user to lp account. Now lp has access to its own file space.

  22. Execute program under the ownership of the file s owner To set up a program to execute under the ownership of the file s owner, you need to alter the permissions. By altering the executable bit (either owner or group) of the program. You will find that the owner s executable bit is not set to x but to s. If you alter the owner s execution status, the permission changes from x to s.

  23. Example passwd stored in /usr/bin has permissions of -r- s--x--x (its owner and group are both root). When running passwd, the program is granted not the user s permissions but the file owner s permissions. The real user is the user who issued the command. The effective user is now the program s owner (root). This is known as the EUID (effective user ID). To change (using chmod) the execution bit from x to s (or from nothing to s) and from s to x substitute s for x as in u+s or g+s

Related


More Related Content