Presentation is loading. Please wait.

Presentation is loading. Please wait.

Getting Started UNIX InKwan Yu Topics Unix Commands Unix System calls C function calls.

Similar presentations


Presentation on theme: "Getting Started UNIX InKwan Yu Topics Unix Commands Unix System calls C function calls."— Presentation transcript:

1 Getting Started UNIX InKwan Yu iyu@cise.ufl.edu

2 Topics Unix Commands Unix System calls C function calls

3 What’s shell? A "shell" is a command interpreter that takes input from a person through the keyboard, issues requests on the user's behalf to the OS, receives the results, and displays them to the user.

4 How many Shells in Unix? zsh (Z Shell) bash (Bourne Again Shell) tcsh (Enhanced C Shell) used interactively csh (C Shell) the same to csh sh (Bourne Shell) used mostly for script exceution ksh (Korn Shell) the same to sh

5 How to find which shell you use? echo $SHELL or echo $shell whereis shell which shell

6 Editors in Unix pico emacs vi ed ……

7 Basic Emacs Commands KeystrokesDescription C-hEnter the online help system. C-x C-sSave the file. C-x C-c Exit emacs. C-x uUndo last edit (can be repeated). C-gGet out of current command operation. C-pUp/down/forward/back by line or character. C-n C-f C-b C-vForward/backward by one screen. M-v C-sSearch forward/backward for characters. C-r C-dDelete next/previous character. Del

8 Useful Unix Commands (1) chgrp - change group ownership chmod - change file permission kill process id - terminate a process pwd - display current working directory ls - list files mv - move or rename files rm file - delete files mkdir - create a directory

9 Useful Unix Commands (2) cd pathname - change working directory man –k man –s section name-in-question ps - check process status cp - copy files cat file - catenate and print

10 Unix files groups & permissions -rw-r--r-- 1 yuchen phd 18432 Oct 27 2003 calendar.xls drwx------ 2 yuchen phd 4096 Jan 5 10:24 fa04/ -rw-r--r-- 1 yuchen phd 11330 Sep 30 13:30 in.htm -rw-r--r-- 1 yuchen phd 924 Jan 5 10:08 index.htm drwx--x--x 2 yuchen phd 4096 Aug 20 16:54 old/ There are three groups in Unix: owner, group & others For each group, it has three permissions: read (r), write (w) & execute (x) rwx (binary 770)

11 Unix processes rain:14% ps –u`whoami` -f UID PID PPID C STIME TTY TIME CMD yuchen 6468 6462 0 10:24:28 pts/44 0:00 tcsh yuchen 19705 19703 0 23:55:41 pts/44 0:00 -tcsh yuchen 19703 19701 0 23:55:41 ? 0:00 /usr/local/sbin/sshd yuchen 6462 19705 0 10:23:38 pts/44 0:00 ksh

12 Some tips (1) How to find the processes belonging to me? How to find the details for some system/function call? How to deal with some exception such as dead loop in Unix? How to debug my code in Unix?

13 Some tips (2) ps -ef|grep userid ps -u `whoami` -f ps -u userid -f man cmd man -s section cmd man -k key kill pid kill -9 -1

14 Some tips (3) ddd (require X window) gdb – with emacs will be useful gdb xxxxx core (“where” to look at the trace stack)

15 Unix System Calls System calls OS API to provide services to user processes C standard library wraps the system calls Why not normal function calls? User / Kernel mode to protect the critical OS resources. Trap or interrupt calls are necessary to go through the user/kernel barrier

16 Unix System Calls FD = OPEN(“FILE”, “RW”); FILE CREATION OPERATION TRAP USER MODE KERNEL MODEL Trap Call : User->Kernel Trap Return : Kernel->User

17 Unix System Calls fork() Create a child process with the same image of parent process Returns 0 for the child Returns child’s process ID for the parent After the call there are two processes in the system with same execution image

18 Unix System Calls fork() – who’s the parent? main() { int i; i = fork(); printf(“%d\n, i); } main() { int i; i = fork(); printf(“%d\n, i); } main() { int i; i = fork(); printf(“%d\n, i); } After fork() 24538 0

19 Unix System Calls execvp() Load a program image (possibly with arguments) Replace the current process image with the newly loaded program Run the new image with the same process ID.

20 Unix System Calls execvp() Do you read “ok?” main() { execvp(“ls”, 0); printf(“ok?\n”); } execvp() After execvp() New execution image of “ls” starts to run New execution image of “ls” starts to run main() { execvp(“ls”, 0); printf(“ok?\n”); } Replace


Download ppt "Getting Started UNIX InKwan Yu Topics Unix Commands Unix System calls C function calls."

Similar presentations


Ads by Google