-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignment02
83 lines (63 loc) · 3.24 KB
/
assignment02
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
writing a shell
===============
You are supposed to write a program, which does the following
* When started, it shows user a prompt. Prompts for root and non-root users differ.
** it could be '$' and '#' sign, for example.
* It expects the user to enter a command.
** The "command" could have arguments. It could look like "ls -al", or "cc -o smth smth.c"
** The "command" can be sent to the background in the way you prefer. The common way would be to use the '&' character at the end of the command". Example: "./longcomputation &"
** The "command" can be located in the directories listed in PATH environment variable, as well as in the current directory.
* When the command have been entered and the "Enter" key have been pressed, the program uses functions
** fork()
** wait() - if process should not run in background.
** exec() family functions (evecvp, execle, etc)
in order to execute a given program.
```
Prompt <---------------------------------|
| |
Input received |
| |
fork() |
| |
is this program a child? |
yes | | no |
| | |
| is this a fg job? |
| | | |
| yes no |
| | | |
execute the wait for the child | |
given program process to end | |
with arguments with wait() | |
by using execvp or | | |
its friends. --------------------|
|
|
|
was exec family function
able to run the other
process?
yes | | no
| |
| print an error
| |
child exits.
```
* You need to provide a makefile. This will be especially useful, if you would have several output object files, and would link those together. We will compile the program by changing to the directory with your github username and typing "make".
hints
======
http://www.cs.ecu.edu/karl/4630/sum01/example1.html
http://www.csl.mtu.edu/cs4411.ck/www/NOTES/process/fork/fork-04.c
http://www.csl.mtu.edu/cs4411.ck/www/NOTES/process/fork/wait.html
https://stackoverflow.com/questions/8319484/regarding-background-processes-using-fork-and-child-processes-in-my-dummy-shel
https://stackoverflow.com/questions/21173622/fork-and-wait-in-a-shell-program
http://linuxgazette.net/111/ramankutty.html
https://stackoverflow.com/questions/4788374/writing-a-basic-shell
https://brennan.io/2015/01/16/write-a-shell-in-c/
manual pages of the system calls you would/might want to use (getpid(), fork(), wait(), execvp() )
assignment link
===============
https://classroom.github.com/a/gYCCo2B0
Deadline
========
11/04/2019 23:59 +0400