COMP7004 - Systems Scripting
Lecture 4: Service Scheduling & Managing Processes
Dr. Vincent Emeakaroha
vincent.emeakaroha@mtu.ie
Semester 2, 2026
Service Scheduling
Enables flexibility in system administration
It might be useful to do a job at a particular time
Delay a job if system is busy
Set the frequency of doing particular jobs
Job scheduling services include:
cron
at
sleep
Automating task scheduling in UNIX uses “at” and “cron
Sleep is used mainly to introduce delays in program
execution
at Scheduler
Can be used to execute command once in the future
Example
To view the list of jobs
Use atq command
To remove a job from the list
Use atrm 3 (removes job listed as number 3)
at 11:45 (press ENTER)
cp /etc/passwd $HOME/tmpFile1 (to exit CTRL + D)
cron Scheduler
Executes jobs at a preset time
Allows jobs to run automatically in the background
Text-based configuration
Uses crontab e command for editing
crontab -l will list the contents to stdout
/etc/cron.allow and /etc/cron.deny can control access
to cron facilities
cron job can be schedules with the following format:
[min] [hour] [day of month] [month] [day of week] [program to be run]
cron Job Formatting Example
[min] 0 59, * runs once a minute
[hour] 0 23, * for every hour
[day of month], 1 31, * for every day
[month], 1 -12, * for every month
[day of week] 0 6, * for every day
Sunday = 0 and Saturday = 6
[program] full path to program to be executed
Example: 15 16 5 * * cp /etc/passwd $HOME/tmpFile
Process Overview
UNIX Processes
Running programs
Monitoring processes
Terminating processes
Program vs Process
Program static file which can be run
Binary executables
Bash scripts
Process A running program
Loaded in physical memory
Stored in virtual memory (swap)
Textbooks use the terms job and process almost
interchangeably
Process Components
Address space map
Status
Owner
Signals
Priority
Resources usage
Sleeping
Stopped
Running
Runable
Zombie
Process Attributes
Process ID PID
Unique identifier for every process
Parent PID PPID
There is mostly a process that starts other child processes
init is the starter process
But in Ubuntu 15.04 and above, it is Systemd
Real and Effective User ID UID and EUID
EUID determines what permission the process has
Real and Effective Group ID GID and EGID
Niceness
Specifies scheduling priority that determines the available CPU
Users can make their process “nicer” to the rest of the system
Control terminal where Stdin, Stdout and Stderr are attached
Process Starting and Ending
Processes are created …
When the system boots
By the actions of another process (more later)
By the actions of a user
By the actions of a batch manager
Processes terminate …
Normally exit
Voluntarily on an error
Involuntarily on an error
Terminated (killed) by the actions a user or a process
Process Lifecycle
Wait
Done
New Ready
Admitted
Scheduler
Dispatches
Interrupt
Run
Exit
I/O
Request
I/O Completed
Process Creation
Unix/Linux
Create a new (child) process with a function call
fork();
Allocates new Process Control Block (PCB)
Clones the calling process (almost)
Copy of parent process address space
Copies resources in kernel (e.g. files)
Places new PCB on
Ready queue
Return value from fork() call produces
0 for child
child PID for parent
exec system call used after a fork() to replace the
process memory space with a new program
Process Creation 2
Whenever a (parent) process calls a fork(), a child process
is created with its own descriptor, including its own copies
of the parents program text, data, and stack segments
The child and parent processes execute in their own
separate address spaces
This means that even though they have access to the same
information, when the child is created, both the child and
its parent each reference its own copy of the information
Process Creation 3
Child process can fork (create) another child
Becomes its parent
When child process finishes
Sends status message to parent
Zombie waits for parent acknowledgment
Process in terminated state
If a parent process dies unexpectedly, its child
processes become
Orphan init (PID 1) becomes parent
Linux Process Tree
Command pstree prints this tree in different Linux distributions
It is known as Process Group in UNIX
Process Control Block (PCB)
Data is stored in a process control block
Information associated with each process
Process state
Program counter
CPU registers
CPU scheduling information
Memory-management information
Accounting information
Operating System maintains this data structure
Running Commands
Input command/script name in a terminal
Shell searches for the command or script
If found, shell forks the command to execute it
How is the command found?
PATH environment variable
which Displays full path to a command
Beware of . in your PATH
How Shell Execute Command
fork
wait
exit
exec
Required job
Parent shell
Child
When you type a command, the shell forks a clone of itself
The child process makes an exec call, which causes it to stop
executing the shell and start executing your command
The parent process, still running the shell, waits for the child
to terminate
Process Running States
Possible process states
Running: executing
Blocked: waiting for I/O
Ready: waiting to be scheduled
Running Processes
Foreground process
Returns control to shell after it finishes
Most common usage
Background process
Returns control to shell immediately
Use & typed after command name to run process
in background mode
Runs concurrently
Process Priority
How much CPU time granted relative to other
processes
nice Sets the priority value at start
renice Changes priority
Ranges
System Range
Solaris 0 to 39
RedHat -20 to 20
Ubuntu -20 to 19
Where
Minus values are highest
Plus values lowest
Signals
Signals are process-level interrupt request
Importance
Means to communicate with processes
Terminal signals
<Ctrl><c> - Terminate process
<Ctrl><z> - Stop (suspend) process
Default is to terminate the process
Can be sent by admin for various purposes
Can be sent by kernel when a process breaks a rule
E.g., division by zero
Common Signals
# Name Description
1 HUP Hangup
2 INT Interrupt
3 QUIT Quit
9 KILL KILL
15 TERM Software Termination
STOP Stop
USR1 User defined Signal
Handling Signals
Process can designate a signal handler for a particular
signal
If no handler, kernel takes some default action
When handler is finished catching signal, execution
continues where the signal was received
Process can request that particular signals be ignored, or
blocked
If signal is received while blocked, one instance of that
signal is buffered until it is unblocked
Sending Signal
kill [-signal] pid
kill sends TERM signal by default
kill [-s ignal] 910 3044
kill -9 pid === kill -KILL pid
“Guarantees” that the process will die
sudo killall USR1 httpd
killall removes need for pid
Process Termination
Besides being able to terminate itself with exit, a process can
be killed by another process using kill command:
kill( pid, sig ) - sends signal sig to process with process-id pid.
One signal is SIGKILL (terminate the target process immediately)
When a process terminates, all the resources it owns are
reclaimed by the system:
process control block reclaimed
its memory is deallocated
all open files closed and Open File Table reclaimed
Note: a process can kill another process only if:
it belongs to the same user
super user
Monitoring System Load
Average number of Runnable processes
Measure of how busy the system is
Performance deteriorates at high loads
Excess number of running processes
Good for creating a baseline
uptime command shows Load average
(5, 10, 15 minutes)
Monitoring Linux Process
ps command
Stands for
Process State
Berkeley Software Distribution (BSD) Sorts by %CPU
Usage
System V Release 4 (SVR4) Sorts by PID
Example: ps aux
top command
Full terminal screen display
Sortable
Can kill and renice processes
ps -ef” Information
UID Username
PID Process ID
%CPU/%MEM - % of System CPU/Memory
PRI/NI - Priority/Nice level
RSS/SIZE - Resident/Total Memory used
STAT - Process State
TIME - CPU time used
CMD Command issued
ps Examples
To list all the processes running in the operating
system, including system processes, enter the
command:
ps ef
To list processes with the parents process ID along
with the process state, enter the command:
ps lf
To find a particular process, enter the command
ps ef | grep processName
Runaway Processes
Uncontrolled processes running on a system (Zombie)
Can eat up your resources
Lists users and PIDs accessing a resource
fuser: Command for identifying process
using particular files
lsof: command for showing a list of open
files and their PID
Kill the process and clean up
Killing Process
If you want to terminate a running process, enter the
command:
kill pid_of_process_to_be_killed
Many a time, if the process is not killed by the “kill”
command, you may need to pass additional option to
ensure that the required process is killed. Use the
following command:
Kill -9 pid_of_process_to_be_killed
Monitoring Window Process
Task Manager
Graphical viewer
Can also sort or kill processes
tasklist
Command line Viewer
Can view associated dll files
wmic utility tool
Can view, start, and kill processes
Remote connection capabilities
Thank You!