CS 590 Programming Environments with UNIX
Download
Report
Transcript CS 590 Programming Environments with UNIX
CS 590
Programming Environments with UNIX
Computer Lab Account
www.cs.uah.edu/account
Course Homepage
www.cs.uah.edu/~kkeen/CS590
LASER Lab N328
Some Background
UNIX
UNIX System V
BSD
POSIX
LINUX
LASER LAB
System Names:
catalina
dakota
conquest
duchess
crusader
havoc
hawker
invader
lightning
marauder
shrike
whirlwind
Remote Access
PuTTY is a free telnet/SSH client
You can download PuTTY here
Upload/Download requires SFTP
You can use PSFTP to
upload/download.
Remote Access from
UNIX/LINUX
ssh username@host
Ex: ssh [email protected]
What you are expected to
already know
bash and simple shell operations
Files and directories
File and directory commands
PATH, LD_LIBRARY_PATH
At least one text editor
cp, mv, scp (secure copy), rm, mkdir, rmdir, tar
Set up environment variables
File structure
/ . ..
Absolute vs. relative paths
File and directory permissions
vi, emacs, pico
Strong C programming skills
Getting Help
The man pages
section 1: User commands
section 2: system calls
section 3: library calls
section 4: special or device files
section 5: file formats and conventions
section 6: games for linux
section 7: macro packages and conventions
section 8: system management commands
UNIX/LINUX System Overview
Apps
Shell
Kernel
H.W.
System call
interface
Multi User
Multi Process system
Every user has a UID
Every user belongs to at least one UNIX
group GID
Root always has UID of 0
Programs and Processes
A program is an executable file
A process is an executing instance of a
program
Kernel Mode vs. User Mode
User mode
Most apps run in this mode
Kernel mode
“trusted” code
System Calls
Kernel
App
C Library
func
func
func
func
func
func
System Call Error Handling
For most system calls, return values
are:
0 – success
Negative number – failure
errno
perror
strerror
perror
void perror (const char *msg);
Prints the text in msg followed by a colon
and text description of the error
number.
perror example
FILE *myFile;
myFile = fopen(“file.txt”, “r”);
if(myFile == NULL) {
perror(“unable to open file”);
}
strerror
char *strerror(int errnum);
Prints out text for given error number.
Can be used as part of a larger error
message.
strerror example
FILE *myFile;
myFile = fopen(“file.txt”, “r”);
if(myFile == NULL) {
fprintf(stderr, “unable to open file:
%s”, strerror(errno));
}
Basic IPC - Signals
Inter Process Communication (IPC).
Most basic form is via signals. Used to
notify a process of some condition.
We can catch signals and
Ignore them
Let default action take place
Call a custom signal handler
Example Program
Files and Directories
http://www.cs.uah.edu/~kkeen/CS590/examples/intr
o/pseudols
More about files and directories in
chapter 4
Time in UNIX
Historically
Calendar Time
Process Time
Clock Time
User CPU Time
System CPU Time
Command Line Arguments
int main(int argc, char** argv)
int main(int argc, char *argv[])
argc – argument count
argv – array of character pointers
Dealing with numbers
atoi
atof
getopt
int getopt(int argc, char* const argv[], const char *optstring);
Function to allow easy parsing of
command line options
Looks for options we specify
Sets optarg and optind
Can specify required argument by using
‘:’ after the option in optstring
getopt_long
Uses two dashes instead of one
Allows longer, more descriptive options.