Add assignment 2

This commit is contained in:
Isaac Shoebottom 2023-09-26 11:27:36 -03:00
parent 7e77743b9d
commit d7cc2be178
12 changed files with 209 additions and 0 deletions

15
Assignment1/.idea/aws.xml Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="accountSettings">
<option name="activeRegion" value="us-east-1" />
<option name="recentlyUsedRegions">
<list>
<option value="us-east-1" />
<option value="us-east-2" />
</list>
</option>
</component>
<component name="connectionManager">
<option name="activeConnectionId" value="sso;us-east-1;https://view.awsapps.com/start" />
</component>
</project>

8
Assignment2/.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

11
Assignment2/.idea/aws.xml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="accountSettings">
<option name="activeRegion" value="us-east-1" />
<option name="recentlyUsedRegions">
<list>
<option value="us-east-1" />
</list>
</option>
</component>
</project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Assignment2.iml" filepath="$PROJECT_DIR$/.idea/Assignment2.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.22)
project(Assignment2 C)
set(CMAKE_C_STANDARD 99)
add_executable(Assignment2 main.c)

Binary file not shown.

View File

@ -0,0 +1,47 @@
(870665) Please input your shell command:
onechild
(870665)Hello, I am a parent process
(870666)Hello, I am a child process
(870665) Please input your shell command:
addnumbers
(870665)Please input number, (0) to terminate
1
(870665)Read 1
(870665)Please input number, (0) to terminate
(870667)The subtotal is: 1
2
(870665)Read 2
(870665)Please input number, (0) to terminate
(870667)The subtotal is: 3
3
(870665)Read 3
(870665)Please input number, (0) to terminate
(870667)The subtotal is: 6
4
(870665)Read 4
(870665)Please input number, (0) to terminate
(870667)The subtotal is: 10
0
(870665)Read 0
(870667)The subtotal is: 10
(870665)The sum is 10
(870665) Please input your shell command:
exec
(870665) Please input exec subcommand
ls
;
a.out sample_run_1.txt solution.c
(870665) Please input your shell command:
processtree
Please input the integer
3
(870665)The value is 0
(870671)The value is 4
(870672)The value is 2
(870676)The value is 3
(870674)The value is 1
(870673)The value is 6
(870675)The value is 5
(870677)The value is 7
(870665) Please input your shell command:
stop

View File

@ -0,0 +1,77 @@
(870697) Please input your shell command:
onechild
(870697)Hello, I am a parent process
(870698)Hello, I am a child process
(870697) Please input your shell command:
onechild
(870697)Hello, I am a parent process
(870699)Hello, I am a child process
(870697) Please input your shell command:
addnumbers
(870697)Please input number, (0) to terminate
3
(870697)Read 3
(870697)Please input number, (0) to terminate
(870700)The subtotal is: 3
5
(870697)Read 5
(870697)Please input number, (0) to terminate
(870700)The subtotal is: 8
7
(870697)Read 7
(870697)Please input number, (0) to terminate
(870700)The subtotal is: 15
0
(870697)Read 0
(870700)The subtotal is: 15
(870697)The sum is 15
(870697) Please input your shell command:
exec
(870697) Please input exec subcommand
ls
-al
;
total 40
drwxr-xr-x 2 hidden fcsgrad 61 Sep 21 23:40 .
drwxr-xr-x 5 hidden fcsgrad 61 Sep 21 11:41 ..
-rwxr-xr-x 1 hidden fcsgrad 26824 Sep 21 23:40 a.out
-rw-r--r-- 1 hidden fcsgrad 1093 Sep 21 23:40 sample_run_1.txt
-rw-r--r-- 1 hidden fcsgrad 5503 Sep 21 23:39 solution.c
(870697) Please input your shell command:
processtree
Please input the integer
5
(870697)The value is 0
(870711)The value is 1
(870708)The value is 2
(870704)The value is 16
(870706)The value is 4
(870709)The value is 20
(870713)The value is 18
(870705)The value is 8
(870715)The value is 10
(870714)The value is 6
(870710)The value is 12
(870707)The value is 24
(870712)The value is 28
(870697) Please input your shell command:
(870718)The value is 3
(870719)The value is 17
(870720)The value is 5
(870722)The value is 21
(870723)The value is 19
(870716)The value is 22
(870725)The value is 9
(870730)The value is 29
(870727)The value is 11
(870726)The value is 7
(870721)The value is 26
(870728)The value is 13
(870731)The value is 23
(870732)The value is 27
(870729)The value is 25
(870717)The value is 14
(870724)The value is 30
(870734)The value is 15
(870733)The value is 31
stop

25
Assignment2/main.c Normal file
View File

@ -0,0 +1,25 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#include <stdbool.h>
int main() {
bool is_looping = true;
// Listen loop
while (is_looping) {
char input[5][100];
char buffer[500];
//Print prompt
printf("[%d]> ", getpid());
if (fgets(buffer, 500, stdin) == NULL) {
break;
}
//split buffer on spaces into input array
sscanf(buffer, "%s %s %s %s %s", input[0], input[1], input[2], input[3], input[4]);
if (strcmp(input[0], "stop") == 0) {
is_looping = false;
}
}
}