Presentation is loading. Please wait.

Presentation is loading. Please wait.

ICS 431 – Operating System. a command-line interpreter. a program that interprets commands and acts as an intermediary between the user and the inner.

Similar presentations


Presentation on theme: "ICS 431 – Operating System. a command-line interpreter. a program that interprets commands and acts as an intermediary between the user and the inner."— Presentation transcript:

1 ICS 431 – Operating System

2 a command-line interpreter. a program that interprets commands and acts as an intermediary between the user and the inner workings of the UNIX system.

3 A system call is a request for service that a program makes of the kernel. System calls are sometimes called kernel calls. fork() exec() wait().

4 The fork() function is used to create a new process from an existing process. creates an exact copy of that process somewhere else in the memory The new process is called the child process, the existing process is called the parent. The parent gets the child's pid returned to him, but the child gets 0 returned to him

5 #include #include int main () { printf("Hello World\n"); fork(); printf("Goodbye World\n"); } OUTPUT: Hello World Goodbye world Goodbye world the name of the header file that provides access to the POSIX operating system APIheader filePOSIXAPI

6 The fork is executed only once, but it returns two different values creates an exact copy of that process somewhere else in the memory The new process is called the child process, the existing process is called the parent. The parent gets the child's pid returned to him, but the child gets 0 returned to him

7 initiates a new program in the same environment in which it is operating. An executable (with fully qualified path. i.e. /bin/ls) and arguments are passed to the function. Note that "arg0" is the command/file name to execute. #include main () { execl("/bin/ls", "/bin/ls", "-r", "-t", "-l", (char *) 0); }

8 Blocks calling process until the child process terminates. If child process has already terminated, the wait() call returns immediately. If the calling process has multiple child processes, the function returns when one returns.

9 /usr/bin/sh department=csse count=3 dir_name=/home/user3/tree PS1=$ PATH=/usr/bin:/usr/contrib/bin:. HOME=/home/user3 SHELL=/usr/bin/sh TERM=70094a Local variables Environment variables Program code

10 Copyright © CCESC Mapúa Tech Syntax: name=value Examples: $ course =ICS431 Assign local variable $ count=3 Assign local variable $ PS1=hi_there$ Update environment variable Return /usr/bin/sh course=ICS431 count=3 dir_name=/home/user3/tree PS1=hi_there$ PATH=/usr/bin:/usr/contrib/bin:. HOME=/home/user3 SHELL=/usr/bin/sh TERM=70094a

11 Syntax: $name Directs the shell to perform variable substitution Example: $ echo $PATH /usr/bin:/usr/contrib/bin:/usr/local/bin $ PATH=$PATH:$HOME:. /usr/bin:/usr/contrib/bin:/usr/local/bin:/home/user3:. $ echo $HOME /home/user3 $ file_name=$HOME/file1 $ more $file_name Return

12 Syntax: $ (command) Example: $ pwd /home/user2 $ curdir=$(pwd) $ echo $curdir /home/user2 $ cd /tmp $ pwd/tmp $ cd $curdir $ pwd /home/user2 Return

13 $ echo $HOME /home/user3 $ env HOME=/home/user3 PATH=/usr/bin:/usr/contrib/bin:/usr/local/bin SHELL=/usr/bin/sh $ set HOME=/home/user3 PATH=/usr/bin:/usr/contrib/bin:/usr/local/bin SHELL=/usr/bin/sh color=lavender count=3 dir_name=/home/user3/tree $ unset dir_name Return

14 Syntax: export variable /usr/bin/sh department=csse count=3 dir_name=/home/user3/tree PS1=hi_there$ PATH=/usr/bin:/usr/contrib/bin:. HOME=/home/user3 SHELL=/usr/bin/sh count=3 department=csse env export

15 /usr/bin/sh local variables department=csse env var TERM=70094a $ vi /usr/bin/sh local variables department=csse env var TERM=70094a /usr/bin/sh local variables department=csse env var TERM=70094a /usr/bin/sh local variables department=csse env var TERM=70094a parent sleeps $ STEP1: fork: program and data spaces are duplicated STEP2:exec: program & local data space are replaced with program & data of requested program (/usr/bin/vi) & program is executed.

16 $ ps –f UID PID PPID C STIME TTY TIME COMMAND user3 6739 3662 0 08:46:40 pts/6 0:00 first_one user3 6738 3662 0 09:55:10 pts/6 0:00 second_one user3 3662 3657 0 08:10:10 pts/6 0:00 csh user3 6892 3662 4 09:55:10 pts/6 0:00 ps -f Return


Download ppt "ICS 431 – Operating System. a command-line interpreter. a program that interprets commands and acts as an intermediary between the user and the inner."

Similar presentations


Ads by Google