Processes – CSC252
Total Page:16
File Type:pdf, Size:1020Kb
Processes – CSC252 PROF. EARL Some slides adopted from Dr. John Carelli and Dr. Lisa Frye User • Programs that the user interacts with User vs or launches themselves Kernel Kernel • Provides services to user space. Space Manages hardware and resources for multiple users. User processes access this space through system calls Hardware Processes https://goo.gl/images/381BdN Processes A single process is the execution of command by the Linux Kernel Every process (besides init) has a Process ID (PID) and Parent Process ID (PPID) Processes are “spawned” from another System Calls Allow a program in user space to interact with the kernel fork() – Allows for a process to create a new sub-process (A child process) The PPID of the new process, would be the PID of the process that called fork() exec() – Execute a new command replace the process with the new one. Sessions The lifetime a user login process When a user logins into a linux machine, a new shell process is created job – A command pipeline ; - Separate Commands & - Run the command in the background Basic Process Commands history – log of past commands jobs – List of currently running jobs kill – Terminal a process fg,bg – Move a process to the foreground/background ps – List processes top – View top running processes uptime – View how long system has been running free – View available memory (RAM) pstree – Show process tree nohup – run command immune to hangups Review the student presentations as posted on D2L (except for ps) The Process Table Data structure that exists in Kernel Space Contains the following: Process ID Process Owner Process Priority Environment variables for each process The Parent Process Location of its code, data, stack, and user area Pending Signals The ps command UNIX command that allows you to view information from the process table. Some Examples: https://www.tecmint.com/ps-command-examples-for-linux-process-monitoring/ Process Initiation init - is the last step when booting a computer (Usually PID 0 or 1) fork(), exec() – Used to create the new processes getty - Create a terminal session login - Login a user Modes User – “Normal” user kernel - root Process Termination Two ways a process can terminate Normal – Process runs and exits normally Abnormal – Terminated via an external control wait() When a process spawns subprocesses, it has to wait until its child process(es) finish before ending Parent process suspends until children are done Zombie Process Terminated, but still in process table Exists so parent can read exit code Orphan Process Parent Terminated Gets handed over to the init process Process States When a process is created, it will exist in one of these states: Suspended / Exit Idle/Waiting Stopped The process is waiting on some event to happen internally Runnable/Ready Process is ready to run and is waiting Idle/Waiting Runnable to be scheduled by the kernel Running Zombie (for an event) / Ready Running Process is currently running Suspended/Stopped Stopped externally, usually by a Sleeping / signal Blocked Sleeping/Blocked Waiting for an Input/Output event or a resource in use by another process Exit Zombie See previous slide. Process Internals Scheduler Decides which processes to run and for how long uses preemptive multitasking – system decides Memory Manger virtual memory System looks like it has more actual memory Magic Number embedded near beginning of file – Indicates the file type Can use file to identify type Process Areas User Code Area - The instructions to run the program Data Area - Data associated with the program Stack Area - Program stack (manage function calls) User Area - Misc. stuff (Opened files, the current directory, etc.) Kernel Area Process Table Page Table – Keep track of where items are stored within memory Scheduling Jobs crontab Allows user to schedule a job Useful stuff man crontab crontab –e - Allows individual users to edit their cron at Allows for launching of a command at a specified time man at.