L5 (1)
L5 (1)
DAVID WANG
COMPUTING SCIENCE AND INFORMATION TECHNOLOGY
OUTLINE
• UNIX process
• System Administration
THE PROCESS
• An instance of a program in execution
• could be multiple instances of same program in execution
• Created by another process as its child
• init as the first process with PID = 1
• Can be killed or stopped by sending it a signal
• Similar to files
• Arranged in a hierarchical structure
• A parent can have multiple children
• A child can have only one parent
• Attributes held in a separate structure
• process: process table
• file: inode
PROCESS ID
• Process is identified by a unique PID (Process ID)
• The ps command displays
• processes
• PIDs
• the command associated with them
• other process information
DISPLAYING PROCESS ATTRIBUTES
$ ps
When a user other than the owner executes the file, the process
will run with user and group permissions set upon it by its owner.
For example, if the file is owned by user root and group wheel, it
will run as root:wheel no matter who executes the file.
SET PERMISSION EXAMPLE
• Given
• -rwx-----x 1 dmah staff 6335 Jun 12 09:49 my_cgi
• read/write/execute for the owner and execute for others
• Perform
• $ chmod u+s my_cgi
• $ chmod g+s my_cgi
• Result
• -rws--S--x 1 dmah staff 6335 Jun 12 09:49 my_cgi
• The first 's' means SUID
• The second ‘S' means SGID
• capitalized because the group does not have execute
permission on the file
SETUID AND SETGID ON DIRECTORIES
• Setting the setuid permission set on a directory
• Ignored on UNIX and Linux systems
• FreeBSD can be configured to interpret it analogously to
setgid
• Setting the setgid permission on a directory
• new files and subdirectories created within it to inherit its
group ID, rather than the primary group ID of the user who
created the file
• the owner ID is never affected, only the group ID
• Only affects the group ID of new files and subdirectories
created after the setgid bit is set, and is not applied to
existing entities
PROCESS STATES
• At any instant of time, a process is in a particular state
• runnable
• running
• sleeping
• suspended
• zombie
CHECKING PROCESS STATES
• $ ps -l
FS UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0O 9853 2039 2015 0 40 20 ? 245 pts/3 0:00 ps
0S 9853 2015 2011 0 40 20 ? 457 ? pts/3 0:00 bash
0S 9853 2011 2005 0 98 20 ? 261 ? pts/3 0:00 csh
• Symbols
• O: Running on CPU
• S: Sleeping
• R: Runnable
• T: Suspended
• Z: Zombie
STATE PROBLEM
• when child dies before parent
• Child leaves behind exit status in process table
• Child turns to zombie state
• Parent may
• pick up exit status; child is now completely dead
• the reason for waiting
• may not wait; child continues to remain in zombie state
• Zombies can’t be killed
• shown as <defunct> in ps output
• when parent dies before child
• Child adopted by init
• PPID of child changes to 1
• When child dies, init picks up the exit status
SIGNALS
• Notification of occurrence of an event
• Every signal associated with a default action (disposition)
• Process may
• perform the default action
• ignore the signal
• catch the signal and invoke a signal-handling function
• 2 signals can’t be ignored or caught
• SIGSTOP
• SIGKILL
• The keyboard and kill command generate signals
• Keyboard issues only a few: SIGINT, SIGQUIT and SIGTSTP
• But the kill command can generate any signal
SIGNALS
Signal Number
Signal
Function
Solaris Linux Name
• A * used in any of the first five fields matches any valid value
• A set of numbers is delimited by a comma. 3,6,9 is a valid field
specified
• Ranges are possible and not be restricted to a single digit. 00-10
includes all integer values between 0 and 10.
SYSTEM ADMINISTRATOR
• Every Unix needs to be administered
• This task is usually entrusted to a single person – the
system administrator
• The administrator mainly uses the root user-id for
performing his/her duties
• The root account and its password are automatically
created at the time of installation of operating system
SYSTEM ADMINISTRATION
RESPONSIVITIES
• System starting & stopping
• File maintenance & backup
• User accounts management
• Software install
• Device install & configuration
• Repetitive tasks automation
• System accounting
• Kernel configuration
• System security
SUPER USER
• Play it safe
• the administrator doesn’t need root all the time
• switch from common account to the superuser if necessary
• The su command (substitute user)
• Log as a regular user
• If root privileges needed, use su to log as root
• Avoid inadvertent errors
• Let su keep a log
• Usage:
• $ su [options] [commands]
• By default, su means su root (requires a password)
• su can be used to switch to non-privileged users
• $ su alice
ADMINISTRATOR’S PRIVILEGES
• The superuser has enormous powers
• any command invoked by superuser has a greater chance of
success than when issues by others
• The superuser can:
• Change the contents or attributes of any file
• Initiate or kill any process (except the essential ones for system)
• Change any user’s password without knowing the existing one
• Use date to set the system clock
• Address all users concurrently with wall
• Limit the maximum size of files for users to create with ulimit
• Control user’s access to the scheduling services like at and cron
• Control user’s access to networking services like FTP, SSH, etc.
USER ADMINISTRATION
• Adding Users create-home
• Removing Users
• The userdel command removes all user entries
• $ userdel oracle
/etc/passwd
• Every user of the system has an entry in /etc/passwd
• Entry format in /etc/password
• User details, for example, name, address, and so on
• Used at the front of the email address for this user
Username:Password:UID:GID:comment:HomeDir:LoginShell
• Example:
• $ grep dawang /etc/passwd
dawang:x:9853:2000:David Wang:/gator1/dawang:/usr/bin/csh
/etc/group
• A group is associated with a separate set of privileges
• A group is comprised of one or more members
• People working on a common project are placed in the
same group, so they are able to read one another’s file
• Every group has an entry in the /etc/group file
• groupname:groupPassword:groupId:users
• Example:
• $ grep student /etc/group
student::2000:
RESTRICTED SHELL
• The administrator can set up a user account with a special
restricted shell like rbash or rksh
• Has to be specified in the last field of /etc/passwd
• A user with a restricted shell can not:
• Use the cd command
• Redefine the PATH
• Redefine the SHELL
• Use a pathname containing a /
• Use the > and >> operators
• A user can only execute programs in the directory
specified in a new unchangeable PATH
BOOTING AND SHUTDOWN
• The startup and shutdown procedures are controlled by
automated shell scripts
• The administrator needs to know the exact sequence of
steps the system follows during the two events
• Things do go wrong, especially during startup, and the
administrator must be able to fix them
BOOTING
• After a machine is powered on, the system looks for all
peripherals, and then goes through a series of steps that
ultimately lead to the loading of the kernel into memory
• The kernel then spawns init process which in turn spawns
further processes
• init maintains the system at a specific run level (state) and
decides which processes to run for each run level
• init is the parent of all system daemons that keep running
all the time
• init spawns a getty process at every terminal
• so that users can login
• init becomes the parent of all shells
RUN LEVELS
• Each run level is normally a single digit (0 to 6), or an s or S
• 0 – system shutdown
• 1 – system administration mode (local file systems mounted)
• 2 – multiuser mode (network file system not available)
• 3 – full multiuser mode
• 5 – the graphical environment mode in linux
• 6 – shutdown and reboot mode
• s or S – single-user mode (file systems mounted)
• A distinct set of processes is scheduled to run in each of
these states
• Run levels are specified in /etc/inittab
• Contains records associating processes with run level and system
action
SHUTDOWN
• Uses the shutdown command to shut the machine down
• Notifies users with wall
• the system going down
• a directive to log out
• After sleeping for a minute, shutdown performs:
• Sends signals to all running processes to terminate normally
• Logs users off and kills remaining processes
• Unmount all secondary file systems using the umount command
• Invokes sync to write all memory restricted data to disk to
preserve the integrity of the file system
• Notifies users to reboot or switch off, or remove the system to
single user-mode
FILE SYSTEMS
• A file system is organized in the form of a directory
structure with its own root
• Modern UNIX systems are set up with multiple file
systems, each meant for a specific purpose
• Every disk must have at least one file system on it
• Advantages of dividing a disk into multiple files systems:
• Separate file system prevents potential encroachment
conflicts that may arise between the various data areas
• Data corruption in one area will not effect data in other file
systems
• Each file system can be backed up separately onto a
single volume of tape.
FILE SYSTEM COMPONENTS
• contains a small boot program and the partition table
boot block • the boot program is responsible for the eventual
loading of the kernel into memory.
inode blocks • contains the inode for every file of the file system