Skip to content

Commit c9f20ea

Browse files
committed
Merge branch 'main' of github.com:chirag-singhal/netprog-assignments into main
2 parents eefc709 + 89f1653 commit c9f20ea

File tree

7 files changed

+82
-3
lines changed

7 files changed

+82
-3
lines changed

P1/readme.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,50 @@
11
# P1 Build your own Bash-like Shell
22

3-
This exercise develops a Bash-like shell with support for chaining process via pipes. Shell also includes input-output redirections, foreground and background prcoesses and inlcudes some new functionalities like double piping(||), triple piping (|||) and shortcut mode(sc).
3+
This exercise develops a Bash-like shell with support for chaining process via pipes. Shell also includes input-output redirections, foreground and background prcoesses and inlcudes some new functionalities like double piping(||), triple piping (|||) and shortcut mode(sc).
4+
5+
# Design
6+
7+
## Shell
8+
9+
The main shell process is a prompting process which shows the prompt and asks for user input.
10+
11+
On succesfully receiving the command, it passes the command to a newly created process which then parses it. This child process is made the leader of a newlhy created process group and all the child processes related to this command will be in this process group. The shell process checks if the command has a & at the end, if it is not present the terminal control is given to this process group (foreground process).
12+
13+
The child process then parses the command and handle all input and output redirections and maintains a structure for it.
14+
15+
The following figures illustrate working of our shell -
16+
17+
![design_1](../assets/p1_design_1.png)
18+
19+
![design_1](../assets/p1_design_2.png)
20+
21+
22+
# Usage
23+
24+
## Chaining commands and Input-Output Redirections
25+
26+
Chaining commands and input-output redirections work as it is like in bash.
27+
28+
ls | wc | wc
29+
ls > dir.txt
30+
ls | wc > count.txt
31+
32+
## Double and Triple Piping
33+
34+
Shell supoports two new pipeline operators `||` and `|||`. For example -
35+
36+
ls -l || wc, cat
37+
ls -l ||| wc, cat, wc -m
38+
39+
It means output of `ls -l` is passed as input to both wc and cat in case of `||` and similarly output of `ls -l` is passed to all the three commands in case of `|||`.
40+
41+
## Short-cut mode
42+
43+
Shell supports a mode called shortu cut mode executed by command `sc`. In this mode, a command can be executed by pressing `Ctrl + C` and then entering a number. This number corresponds to index in lookup table created and deleted by commands `sc -i <ind> <command>` and `sc -d <ind> <command>`.
44+
45+
sc -i 2 ls | wc
46+
sc -i 32 ls -l
47+
sc -d 2 ls | wc
48+
49+
# How to run
50+
make run_shell

P2/readme.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
11
# P2 Cluster Shell
22

3-
This exercise develops a shell which extends to a cluster of machines operating over the network. There is a central server which coordinates the operations and there are multiple clients/nodes which perform the bash commands and communicate to other nodes via server.
3+
This exercise develops a shell which extends to a cluster of machines operating over the network. There is a central server which coordinates the operations and there are multiple clients/nodes which perform the bash commands and communicate to other nodes via server.
4+
5+
# Design
6+
7+
# Server
8+
9+
The server starts before all other clients and starts listening for connections from the clients. As soon as a node starts the client program, it automatically connects to the server. This connection is used to receive commands from the client and respond back with the output of the command. The entire architecture supports executing different sub-commands on different nodes. The server parses the sub-command and determines where the sub-command needs to be sent for processing. The server then starts a temporary connection with the node and the sub-command is sent and the output is received. The temporary connection is closed.
10+
11+
# Client
12+
13+
The client itself has a client-side and a server-side. The client-side connects to the server as soon as the program is started. The server-side operates on a forked child and starts listening for processing of the sub-commands from the server. Client-side is associated with the shell. As soon as the user enters a command, it is dispatched to the server using the already established TCP connection.
14+
15+
The following figures illustrate working of our shell -
16+
17+
![design_1](../assets/p2_design_1.png)
18+
19+
# Command
20+
21+
The commands are of the form `n1.ls | n2.wc | ...`. The nodes are identified by ‘n’ followed by the node ID. It implies that that particular sub-command is executed on that node. If there is no node identifier, then the command is assumed to be redirected to the self-node (nonetheless, it still passes through the server instead of directly executing). If ‘n*’ is the identifier, then that sub-command is executed in all the nodes. The outputs from all the nodes are then concatenated and piped to the next sub-command by the server. The pipe ‘|’ indicates that the server acts as a common medium for writing to and reading from the nodes. The “nodes” command displays all the nodes participating in the network. It is displayed in the format of “name” and “ip” on each line for each node.
22+
23+
24+
25+
# How to Run:
26+
27+
The following command is run on the server machine. It compiles and runs the server executable.
28+
29+
make run_server
30+
31+
The following command is run on the server machine. It compiles and runs the server executable.
32+
33+
make run_client
34+
35+
To exit the process you can press Ctrl + C, regardless of client or server.

P3/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# P3 Group Chat Management System
22

3-
This exercise develops a group chat system which allows users to create groups, list all groups on server, join group, send private and group messages and receive messages in online as well as offline mode. The chat system also implements a option which can be set for a group where users who joins a group after < t > seconds from the time of message creation also receives it.
3+
This exercise develops a group chat system which allows users to create groups, list all groups on the server, join groups, send private and group messages and receive messages in online as well as offline mode. The chat system also implements an option which can be set for a group where users who join a group after < t > seconds from the time of message creation also receive it.

assets/p1_design_1.png

65 KB
Loading

assets/p1_design_2.png

57.1 KB
Loading

assets/p2_design_1.png

95.4 KB
Loading

assets/p3_design_1.png

118 KB
Loading

0 commit comments

Comments
 (0)