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?

  • 1
    What's your actual question here? You've already fully answered the questions you've been set and we don't grade answers, here. Open-ended questions don't work well in the Stack Exchange format. – David Richerby Feb 17 at 17:51
  • This question is almost exclusively about Windows, and not at all about any underlying scientific concept. Part d is unrelated (not about Windows, but not about science either); you might want to ask about it separately. – Gilles 'SO- stop being evil' Feb 18 at 8:05

a) You seem to have this down
b) I would add that double clicking a file from the explorer (which is what most Windows users do) closely resembles typing the filename in a command prompt. This allows non-savvy users to work with files even if they are not aware of the program required to deal with them, and they won't have to pick what program to use if they don't know how to.
c) No problem here
d) I think what they are getting at here is that execve allows a script to be run without the caller needing to know how to run it. For example, a program can run a Python program without knowing it needs the python interpreter. (end of answer)

The difference being: it gets the information of how to execute the file from a header in the file rather than a "default application" table and matching the filename extension. This has the added benefit for the creator of the file that they are they ones deciding how the file is run, not the operating system. Also, the extension does not matter this way.

  • I don't really understand what you meant in (b), it seems like clicking is something non-tech savvy people will do rather than using the command prompt, but I think the feature here is referring to the command prompt, to my understanding – Prashin Jeevaganth Feb 17 at 17:43
  • And am I right to say that what you meant in (d), in cmd there was actually a need to know that a Python program needs a Python interpreter, but in execve there is no need to? – Prashin Jeevaganth Feb 17 at 17:47
  • @PrashinJeevaganth I believe double clicking the file in explorer lets explorer execute the command in the same cmd like fashion (this is what happens behind the gui, invisible to the user). This is why I made this link, the default application system makes it easier for most users (1), the command example demonstrates it (2) and the gui implements it and is used by most users (3) – Gert Feb 17 at 17:52
  • @PrashinJeevaganth in cmd the OS would know the program needs a python interpreter if the python interpreter is set as a default program for python scripts. With execve, the script itself is tellling the caller what it requires to be executed. In both cases we need to know the python interpreter is required, it's just defined in a different place – Gert Feb 17 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.