Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. In UNIX, a program tries to run ls command. Describe the differences between

ID: 3693936 • Letter: 1

Question

1. In UNIX, a program tries to run ls command. Describe the differences between the following two different approaches:

(a) directly executing execvp() system call to run the ls command in the program and

(b) spawning a child process by executing fork() system call and have this child process call execvp() to run the ls command. (10 pts)

2. a) When you logon  to the eve machine or any UNIX/Linux system, you are running a shell. What is a shell? (10 pts)

b) After you logon, you type ls command and hit "enter", who executes the  ls command? what's happen to the shell? (10 pts)

3. In the UNIX canonical mode of the terminal driver, the translation happens between the tty and the process. What are the translations for the following:

(a) when you type ‘Return” (ASCII 13), what does the process see?

(b) when a program prints newline, what does tty see?

(c) the program see nothing until you type which key?

Explanation / Answer

Directly executing execvp () system call to run the ls command in the program

            The created child process does not have to run the same program as the parent process does. The exec type system calls allow a process to run any program files, which include a binary executable or a shell script. On this page, we only discuss one such system call: execvp(). The execvp() system call requires two arguments:

            When execvp() is executed, the program file given by the first argument will be loaded into the caller's address space and over-write the program there. Then, the second argument will be provided to the program and starts the execution.

Fork ()

            int fork() turns a single process into 2 identical processes, known as the parent and the child. On success, fork() returns 0 to the child process and returns the process ID of the child process to the parent process. On failure, fork() returns -1 to the parent process, sets errno to indicate the error, and no child process is created. Actually the child process will have its own unique PID.

The following program illustrates a simple use of fork, where two copies are made and run together (multitasking)

The Output of this would be:

The shell

            The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks the username and password, and then starts another program called the shell. The shell is a command line interpreter (CLI). It interprets the commands the user types in and arranges for them to be carried out. The commands are themselves programs: when they terminate, the shell gives the user another prompt (% on our systems).

Filename Completion - By typing part of the name of a command, filename or directory and pressing the [Tab] key, the tcsh shell will complete the rest of the name automatically. If the shell finds more than one name beginning with those letters you have typed, it will beep, prompting you to type a few more letters before pressing the tab key again.

Type ls command and hit "enter", who executes the  ls command? What’s happen to the shell?

            This program executes the ls command and displays the filenames and extensions separately

Return

            The definition of a function is traditionally that is returns a single value, and does not output anything. A procedure, on the other hand, does not return a value, but may produce output. A shell function may do neither, either or both. It is generally accepted that in shell scripts they are called functions

Newline

            as LineFeed (newline in Unix) or (newline in Windows systems).

The program sees nothing until you type which key

Do nothing, unless assigned a specific function in a particular program.