Skip to content

Commit c7bae69

Browse files
authored
Update README.md
1 parent 231fa5c commit c7bae69

File tree

1 file changed

+126
-69
lines changed

1 file changed

+126
-69
lines changed

README.md

Lines changed: 126 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,126 @@
1-
Explanations:
2-
3-
System Calls:
4-
fork() to create a child process to aid the parent process in completing task
5-
waitpid() to wait for the child process to finish, so that parent can start working
6-
execv() to pass arguments to executable binaries
7-
8-
Working:
9-
The shell runs inside main() in a while loop.
10-
First the user input is taken in raw form using read_command() method.
11-
Then this entered command is passed to parse_command method which trims spaces from both sides, tokenize the command.
12-
After calling parse_command(), we have tokens of the command which are used to run the command.
13-
These tokens are sent to execute_command() method, in order to get executed.
14-
The functions check if the first token is a vliad command or not.
15-
Based on the outcomes, if the first token is a valid command, the coressponding method to execute it is called.
16-
In the method, using the tokens, the complete argument set is extracted and ran within the fucntion in case of internal commands and using the dedicated executables in case of external commands
17-
Every External command is run by first changing the flow of program from the current program to the dedicated executable.
18-
This is done using fork() and execv(), while to run the further process smoothly by the parent process waitpid is used.
19-
In the execuatbles the tokens are checked for specific signature of working commands, and no matching are run.
20-
This cycles continues, till the users wishes.
21-
22-
Note:
23-
To handle command with meaningful spaces, like name of a file, double qoutes should be used to enter such name. Example- "hello world.txt"
24-
25-
Error Handling:
26-
Check for file successfully opend
27-
Check for process created successfully
28-
Check for process ended successfully
29-
Check for Insufficient arguments for command
30-
Check for excess arguments for command
31-
Check for unrecognized command
32-
Check for Invalid command type
33-
Check for File do not exits
34-
Check for argument validity in context
35-
36-
Commands:
37-
cd - change the current working directory of shell
38-
pwd - get the current working directory of shell
39-
history - to check the entered commands
40-
echo - to show user input back
41-
exit - to exit the shell
42-
cat - to print files
43-
ls - to show content of current directory
44-
date - to show the current time
45-
rm - to remove a file
46-
mkdir - to make directory
47-
48-
Specific Inbuilt Functions:
49-
fork() - to create a child process
50-
waitpid() - to wait parent for child process to finish
51-
execv() - to call executable
52-
exit() - to exit from a program
53-
chdir() - to change the current working directory
54-
getcwd() - to get the current working directory
55-
getlogin() - to get the user logged in currently
56-
scandir() - to scan the contents of a directory
57-
fopen() - to open a file for reading/wrirting
58-
fclose() - to close a file
59-
fseek() - to reach a particular point in a file
60-
fgets() - to read a line from a stream
61-
fputs() - to transfer content to a stream'
62-
time() - to get time in epoch form
63-
strftime() - to format the time form
64-
gmtime() - to get utc time
65-
localtime() - to get local time
66-
67-
68-
Known Bug:
69-
Using mkdir, changes access permission in the applied folder.
1+
2+
# System Calls:
3+
4+
-> fork() to create a child process to aid the parent process in completing task
5+
6+
-> waitpid() to wait for the child process to finish, so that parent can start working
7+
8+
-> execv() to pass arguments to executable binaries
9+
10+
11+
# Working:
12+
13+
-> The shell runs inside main() in a while loop.
14+
15+
-> First the user input is taken in raw form using read_command() method.
16+
17+
-> Then this entered command is passed to parse_command method which trims spaces from both sides, tokenize the command.
18+
19+
-> After calling parse_command(), we have tokens of the command which are used to run the command.
20+
21+
-> These tokens are sent to execute_command() method, in order to get executed.
22+
23+
-> The functions check if the first token is a vliad command or not.
24+
25+
-> Based on the outcomes, if the first token is a valid command, the coressponding method to execute it is called.
26+
27+
-> In the method, using the tokens, the complete argument set is extracted and ran within the fucntion in case of internal commands and using the dedicated executables in case of external commands
28+
29+
-> Every External command is run by first changing the flow of program from the current program to the dedicated executable.
30+
31+
-> This is done using fork() and execv(), while to run the further process smoothly by the parent process waitpid is used.
32+
33+
-> In the execuatbles the tokens are checked for specific signature of working commands, and no matching are run.
34+
35+
-> This cycles continues, till the users wishes.
36+
37+
38+
# Note:
39+
40+
-> To handle command with meaningful spaces, like name of a file, double qoutes should be used to enter such name. Example- "hello world.txt"
41+
42+
43+
# Error Handling:
44+
45+
-> Check for file successfully opend
46+
47+
-> Check for process created successfully
48+
49+
-> Check for process ended successfully
50+
51+
-> Check for Insufficient arguments for command
52+
53+
-> Check for excess arguments for command
54+
55+
-> Check for unrecognized command
56+
57+
-> Check for Invalid command type
58+
59+
-> Check for File do not exits
60+
61+
-> Check for argument validity in context
62+
63+
64+
# Commands:
65+
66+
-> cd - change the current working directory of shell
67+
68+
-> pwd - get the current working directory of shell
69+
70+
-> history - to check the entered commands
71+
72+
-> echo - to show user input back
73+
74+
-> exit - to exit the shell
75+
76+
-> cat - to print files
77+
78+
-> ls - to show content of current directory
79+
80+
-> date - to show the current time
81+
82+
-> rm - to remove a file
83+
84+
-> mkdir - to make directory
85+
86+
87+
# Specific Inbuilt Functions:
88+
89+
-> fork() - to create a child process
90+
91+
-> waitpid() - to wait parent for child process to finish
92+
93+
-> execv() - to call executable
94+
95+
-> exit() - to exit from a program
96+
97+
-> chdir() - to change the current working directory
98+
99+
-> getcwd() - to get the current working directory
100+
101+
-> getlogin() - to get the user logged in currently
102+
103+
-> scandir() - to scan the contents of a directory
104+
105+
-> fopen() - to open a file for reading/wrirting
106+
107+
-> fclose() - to close a file
108+
109+
-> fseek() - to reach a particular point in a file
110+
111+
-> fgets() - to read a line from a stream
112+
113+
-> fputs() - to transfer content to a stream'
114+
115+
-> time() - to get time in epoch form
116+
117+
-> strftime() - to format the time form
118+
119+
-> gmtime() - to get utc time
120+
121+
-> localtime() - to get local time
122+
123+
124+
# Known Bug:
125+
126+
-> Using mkdir, changes access permission in the applied folder.

0 commit comments

Comments
 (0)