I am starting out in Operating Systems module and these question really caught me off-guard. These questions have no solutions.
(a) In Windows, start a command line shell, eg. cmd. Assuming that you are in a directory with some standard document file types, eg. .doc, .pdf, .ppt, etc. Just try type the filename itself.
To elaborate, this question assumes there is a PDF file, e.g. U5-UnixProcess.pdf (any PDF file will do), in the same directory and you have a PDF reader. The following example illustrates how to start a process from a document: c:> U5-UnixProcess.pdf
What happens? What program is running? Is it the PDF file running?
(b) Explain what is the rationale for such a feature in Windows.
(c) How is it that Windows knows what to do with the file? (Hint: use the right mouse button).
(d) Unix has a related feature. Read the man page for execve and explain the feature and how you can use it?
Here are my answers based on my understanding. I have tried looking for answers but there seems to be no sources which explains such delicate issues.
a) When we type the filename, the command line shell would search for the filename within the current directory. If it is not found, then it would search directories that are listed in the PATH enviroment variable. Once it has found the file, it would look up the file's extension to find out which application handles the type of file, which would be the PDF reader if the file extension is .pdf. After that, it would start the application as a new process and pass it the name of the file.
In this whole process, an application that is able to handle the file is running and not the file itself.
b) The command line shell allows users to have access to more commands other than what their graphic user interface provides, such as the viewing of hidden files.
c) You can set the default application to use when opening a file to tell Windows what to do with the file. If there are no applications that can run the file, then the file would not open.
d) I mostly just copied off a segment of TutorialsPoint for this one. Don't really understand the application of "how to use it" here.
execve() is a syscall that transforms the calling process into a new process, and is of the signature of
int execve(const char *path, char *const argv, char *const envp);
execve() executes the program pointed to by path. path must be either a binary executable, or a script starting with a line of the form "#! interpreter [arg]". In the latter case, the interpreter must be a valid pathname for an executable which is not itself a script, which will be invoked as interpreter [arg] filename.
argv is an array of argument strings passed to the new program. envp is an array of strings, conventionally of the form key=value, which are passed as environment to the new program. Both argv and envp must be terminated by a null pointer. The argument vector and environment can be accessed by the called program’s main function, when it is defined as
int main(int argc, char *argv, char *envp).
Can anyone reinforce my understanding on these topics, and perhaps direct me to sources where I can read up on these?