0% found this document useful (0 votes)
38 views13 pages

Unix Process Control: by Greg Scott

This document discusses Unix process control and permissions. It covers: 1) Access permissions which control who can access and modify files using read, write and execute permissions for the owner, group and others. 2) The chmod command which is used to change permissions using either symbolic or absolute modes. 3) Running executable files by making them executable and ensuring the path includes their directory. 4) Running processes in the foreground and background. Background processes allow continuing command entry while processes run. 5) Terminating processes using the kill command. Maintaining processes using nohup to prevent termination on logout. 6) Scheduling future processes using the at command to run commands at specified times

Uploaded by

sameer3vm
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views13 pages

Unix Process Control: by Greg Scott

This document discusses Unix process control and permissions. It covers: 1) Access permissions which control who can access and modify files using read, write and execute permissions for the owner, group and others. 2) The chmod command which is used to change permissions using either symbolic or absolute modes. 3) Running executable files by making them executable and ensuring the path includes their directory. 4) Running processes in the foreground and background. Background processes allow continuing command entry while processes run. 5) Terminating processes using the kill command. Maintaining processes using nohup to prevent termination on logout. 6) Scheduling future processes using the at command to run commands at specified times

Uploaded by

sameer3vm
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Unix Process Control

By Greg Scott
Access permissions
• Access permissions allow you to determine who can
have access to your personal files and directories;
they control who can do what to a file.
– Permissions affect three categories of users:
• The owner of the file (user)
• A member of the file’s group (group)
• All other users that have access to the system (other)
– Permissions allow three types of access to a file:
– Read (r)
– Write (w)
– Execute or search (x)
• The ls –l command displays the permissions for each
file in the directory.
Access permissions
$ ls -l
total 6
-rw-r--r-- 1 gscott36 guest 133 Jun 28 03:31 July
-rw-r--r-- 1 gscott36 guest 8 Apr 27 01:45 upfname
-rw-r--r-- 1 gscott36 guest 3150 Jun 19 14:15 usstates.dat
• The first character in each line identifies the file type. A
dash (-) in this position indicates an ordinary file, while a d
indicates a directory
• The next nine characters of the line indicate the current
three access types (rwx) for each of the three categories
of users: the user, his group and others.
• If a user is granted a particular access type, the
corresponding letter appears in the listing; if permission is
denied for that access, a dash (-) appears
Changing permissions: chmod
• symbolic mode: chmod symkey file [ file … ]
– The symkey is comprised of the following components:
[ who][+|-|=][ mode]
– The who component of the key can contain one or more of the
characters: u, g, o, or a, representing user, group, other, or all
three categories, respectively. If omitted, a is used by default.
– The second component must be one of three characters: +, -, or
=, representing adding, removing, or explicitly setting the mode,
respectively
– The mode component can be any combination of r, w, or x,
representing read, write,or execute/search permissions,
respectively
– The three components must be entered in order with no spaces
between them. Multiple keys can be specified; each is separated
by commas (and no spaces).
Example: chmod u=rw,g=r,o-rwx file will give file owner
read and write, gives group read, and takes all
permissions away from others. Exercise: Try this!
Changing permissions: chmod
• absolute mode: chmod abskey file [ file … ]
– The key is comprised of three digits, each of which
represents the permissions for a category of user ( 1st=
owner, 2nd=group, 3rd=other)
– Each digit is determined by assigning a number to the
various permissions: r=4, w=2, and x=1.
– The value 0 is used if a permission is to be denied
– Permission values are added together to give a number
ranging from 0 to 7
Example, to make the file myfile readable and writable by
the owner and group, but read-only for all others, use
the command: chmod 664 myfile
Exercise: give the files in your shells directory read,
write and execute permission for yourself.
Running an Executable file
• You can run any file that has executable permission at the command
prompt as though it was a regular Unix command by typing the
filename and pressing return.
• When a file is run at the command prompt, the directories found in
the PATH variable(a shell environment variable) are searched for the
file named as the command. To see the current setting of PATH, type
:
echo $PATH
• If the path to the file is not included in the PATH variable, it can be be
updated by the command: PATH=$PATH:newdir.
• To make this a permanent change, edit the .profile and place the
command there.
• A file can be run with the shell command sh (Bourne shell) placed
before its name, even when it does not have execute permission.
Example: sh filename
Exercise: a) Try to run the file while1.sh as a command. Did the shell
find it? b) Run it with the sh shell command. c) Update your path to
include current directory, and do a) again. Does is run this time?
Process Control
Your login shell process is the parent process of the
commands that you execute. It normally waits for its child
processes to terminate before prompting you for the next
command. The child is running in the foreground. You can
tell the shell not to wait for a child, but to continue
accepting additional commands by running a process in
the background.
• To run a command in the background, append the
ampersand (&) metacharacter to the end of a command
line. The shell will return with a prompt immediately:
$ command &
586
• The shell displays the child process ID when you execute
a command in the background. The PID can be used to
monitor the background process with the ps command.
Background processes
• To demonstrate background process we will
introduce a few new commands:
– sleep N– makes the the shell wait N seconds
– banner text – displays text in large letters on the screen.
– find – find files with specified attributes and execute a an
optional command.
Exercise 1: create a file called commands with the
following four comands on separate lines, and give it
execute permission.
sleep 10 ; banner one; sleep 10; banner two
a)Run it first in the foreground, b) then in the background.
Check its status with ps.
Background processes
• Background execution is useful for commands that take a
long time to finish. It is not appropriate for interactive
programs such as vi.
• When you run a command in the background, you should
redirect the command output to a file; otherwise, it will
appear on the screen at unpredictable times.
• Exercise2: Background processes
Run the following command to find all files named core
And print their names,with output redirected to corefiles:
find / -name core –print 1> corefiles 2>/dev/null
&
Note the PID number displayed after running the
command.. How will you know when the find is done?
Terminating a process
The kill command: Some processes placed in the
background may become unnecessary and need to be
terminated. For this we use the kill command:
kill [ - signal ] pid [ pid … ]
– The kill command can take any signal number from 1-
31 as an option. The default is termination signal (15)
which can be trapped by a process, allowing it to clean
up before it terminates. Signal 9 is an immediate kill.
Use it as a last resort because processes cannot trap it
to clean up first
– kill takes process ID numbers as its arguments. You
must be the owner of these processes to kill them.
Example: to kill a process with PID=483, enter: kill 483
Exercise: Run the find command(previous slide)
again and kill it.
Maintaining a process
• When a process is running in the background, logging out
will terminate it. If you wish to run a long process in the
background that you don’t want to terminate when you
log out, you can protect that process using the nohup
command:
nohup command [ arguments … ] &
– The nohup command redirects the output of the specified
command to the file nohup.out if output redirection is not
otherwise specified.
Exercise: a) run the command sleep 60 in the
background, then logout. Log back in and check your
processes. Is the sleep command still running? b) Now
run the command again with nohup in the background.
After logging out and back in, is the sleep command
still running? c) run the file commands with nohup in
the background. After logging out and back in, see if
you have a file called nohup.out. What’s in it?
Future scheduling
• The at command- At times, you may want to have a
program run at a later time, when the system is not being
used so heavily. at will execute another command at any
specified time.
at [ options ] time [ date ][+ incr]
– options are
• l – list your at jobs waiting to be run
• r – remove an at job, ex at –r 474285600.a
• m- send mail message after job is run
– time formats:- 2am, 7pm, 1530, now
– date formats- Wed, July 27, today, tomorrow
– incr formats- 2 minutes, days, weeks, months, years
– reads its input from stdin. If stdin comes from your keyboard (i.e.,
you have not redirected it), complete the command by entering
lines until <ctrl>d is typed.
Future scheduling
Examples: To find out who is still on the system at 10:15 pm tonight use
the command:
$ at 1015pm
> date
> who
> <ctrl>d
– The at command will mail the standard output of the executed
command to your system mailbox, or you can specify output
redirection with the delayed command to save stdout to a file of your
choice:
$ at 1015pm
> date > at_data
> who >> at_data
> <ctrl>d
Exercise: Have the at command run the command
banner hello two minutes in the future.

You might also like