240 likes | 410 Views
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:. Remote Access.
E N D
Computer Lab Accountwww.cs.uah.edu/account • Course Homepagewww.cs.uah.edu/~kkeen/CS590 • LASER Lab N328
Some Background • UNIX • UNIX System V • BSD POSIX • LINUX
LASER LAB System Names:
Remote Access • PuTTY is a free telnet/SSH clientYou can download PuTTY here • Upload/Download requires SFTPYou can use PSFTP to upload/download.
Remote Access from UNIX/LINUX • ssh username@hostEx: ssh kkeen@havoc.cs.uah.edu
What you are expected to already know • bash and simple shell operations • Files and directories • File structure • / . .. • Absolute vs. relative paths • File and directory permissions • File and directory commands • cp, mv, scp (secure copy), rm, mkdir, rmdir, tar • Set up environment variables • PATH, LD_LIBRARY_PATH • At least one text editor • vi, emacs, pico • Strong C programming skills
Getting Help • The man pagessection 1: User commandssection 2: system callssection 3: library callssection 4: special or device filessection 5: file formats and conventionssection 6: games for linuxsection 7: macro packages and conventionssection 8: system management commands
UNIX/LINUX System Overview Apps Shell Kernel System call interface H.W.
Multi UserMulti 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 C Library App 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/intro/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.