feat: update structure
This commit is contained in:
24
cs2106/labs/lab2/part1/autograder/grade.sh
Executable file
24
cs2106/labs/lab2/part1/autograder/grade.sh
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if we have enough arguments
|
||||
|
||||
# Delete temporary files
|
||||
|
||||
# Compile the reference program
|
||||
|
||||
# Generate reference output files
|
||||
|
||||
# Now mark submissions
|
||||
|
||||
#
|
||||
# Note: See Lab02Qn.pdf for format of output file. Marks will be deducted for missing elements.
|
||||
#
|
||||
|
||||
# Iterate over every submission directory
|
||||
# Compile C code
|
||||
# Print compile error message to output file
|
||||
# Generate output from C code using *.in files in ref
|
||||
# Compare with reference output files and award 1 mark if they are identical
|
||||
# print score for student
|
||||
# print total files marked.
|
||||
|
||||
5
cs2106/labs/lab2/part1/autograder/ref/s1.in
Normal file
5
cs2106/labs/lab2/part1/autograder/ref/s1.in
Normal file
@@ -0,0 +1,5 @@
|
||||
1
|
||||
3
|
||||
5
|
||||
3
|
||||
4
|
||||
7
cs2106/labs/lab2/part1/autograder/ref/s2.in
Normal file
7
cs2106/labs/lab2/part1/autograder/ref/s2.in
Normal file
@@ -0,0 +1,7 @@
|
||||
382
|
||||
44
|
||||
112
|
||||
95
|
||||
hello
|
||||
world
|
||||
12
|
||||
4
cs2106/labs/lab2/part1/autograder/ref/s3.in
Normal file
4
cs2106/labs/lab2/part1/autograder/ref/s3.in
Normal file
@@ -0,0 +1,4 @@
|
||||
3.4
|
||||
5.4
|
||||
1
|
||||
2.3
|
||||
42
cs2106/labs/lab2/part1/autograder/ref/sum.c
Normal file
42
cs2106/labs/lab2/part1/autograder/ref/sum.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "utils.h"
|
||||
|
||||
#define MAX_STR_LEN 128
|
||||
|
||||
void strip(char *str) {
|
||||
while(*str) {
|
||||
if(*str == '\n')
|
||||
*str = '\0';
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
char str[MAX_STR_LEN];
|
||||
int nums[128];
|
||||
int count=0;
|
||||
int res = 0;
|
||||
|
||||
while(!feof(stdin)) {
|
||||
char *res = fgets(str, MAX_STR_LEN, stdin);
|
||||
|
||||
if(res){
|
||||
strip(str);
|
||||
int val = atoi(str);
|
||||
|
||||
if(val){
|
||||
nums[count++] = val;
|
||||
}
|
||||
else
|
||||
printf("%s is not a non-zero integer.\n", str);
|
||||
}
|
||||
}
|
||||
|
||||
res = sum(nums, count);
|
||||
printf("Item count is %d\n", count);
|
||||
printf("The sum is %d\n", res);
|
||||
exit(res);
|
||||
}
|
||||
|
||||
10
cs2106/labs/lab2/part1/autograder/ref/utils.c
Normal file
10
cs2106/labs/lab2/part1/autograder/ref/utils.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "utils.h"
|
||||
|
||||
int sum(int sum_array[], int n) {
|
||||
int i, res = 0;
|
||||
|
||||
for(i=0; i<n; i++)
|
||||
res += sum_array[i];
|
||||
|
||||
return res;
|
||||
}
|
||||
2
cs2106/labs/lab2/part1/autograder/ref/utils.h
Normal file
2
cs2106/labs/lab2/part1/autograder/ref/utils.h
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
int sum(int [], int);
|
||||
42
cs2106/labs/lab2/part1/autograder/subs/A0183741Y/sum.c
Normal file
42
cs2106/labs/lab2/part1/autograder/subs/A0183741Y/sum.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "utils.h"
|
||||
|
||||
#define MAX_STR_LEN 128
|
||||
|
||||
void strip(char *str) {
|
||||
while(*str) {
|
||||
if(*str == '\n')
|
||||
*str = '\0';
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
char str[MAX_STR_LEN];
|
||||
int nums[128];
|
||||
int count=0;
|
||||
int res = 0;
|
||||
|
||||
while(!feof(stdin)) {
|
||||
char *res = fgets(str, MAX_STR_LEN, stdin);
|
||||
|
||||
if(res){
|
||||
strip(str);
|
||||
int val = atoi(str);
|
||||
|
||||
if(val){
|
||||
nums[count++] = val;
|
||||
}
|
||||
else
|
||||
printf("%s is not a non-zero integer.\n", str);
|
||||
}
|
||||
}
|
||||
|
||||
res = sum(nums, count);
|
||||
printf("Item count is %d\n", count);
|
||||
printf("The sum is %d\n", res);
|
||||
exit(res);
|
||||
}
|
||||
|
||||
10
cs2106/labs/lab2/part1/autograder/subs/A0183741Y/utils.c
Normal file
10
cs2106/labs/lab2/part1/autograder/subs/A0183741Y/utils.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "utils.h"
|
||||
|
||||
int sum(int sum_array[], int n) {
|
||||
int i, res = 0;
|
||||
|
||||
for(i=0; i<n; i++)
|
||||
res += sum_array[i];
|
||||
|
||||
return res;
|
||||
}
|
||||
2
cs2106/labs/lab2/part1/autograder/subs/A0183741Y/utils.h
Normal file
2
cs2106/labs/lab2/part1/autograder/subs/A0183741Y/utils.h
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
int sum(int [], int);
|
||||
40
cs2106/labs/lab2/part1/autograder/subs/A0281754H/sum.c
Normal file
40
cs2106/labs/lab2/part1/autograder/subs/A0281754H/sum.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "utils.h"
|
||||
|
||||
#define MAX_STR_LEN 128
|
||||
|
||||
void strip(char *str) {
|
||||
while(*str) {
|
||||
if(*str == '\n')
|
||||
*str = '\0';
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
char str[MAX_STR_LEN];
|
||||
int nums[128];
|
||||
int count=0;
|
||||
int res = 0;
|
||||
|
||||
while(!feof(stdin)) {
|
||||
char *res = fgets(str, MAX_STR_LEN, stdin);
|
||||
|
||||
if(res){
|
||||
strip(str);
|
||||
int val = atoi(str);
|
||||
|
||||
if(val){
|
||||
nums[count++] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res = sum(nums, count);
|
||||
printf("Item count is %d\n", count);
|
||||
printf("The sum is %d\n", res);
|
||||
exit(res);
|
||||
}
|
||||
|
||||
10
cs2106/labs/lab2/part1/autograder/subs/A0281754H/utils.c
Normal file
10
cs2106/labs/lab2/part1/autograder/subs/A0281754H/utils.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "utils.h"
|
||||
|
||||
int sum(int sum_array[], int n) {
|
||||
int i, res = 0;
|
||||
|
||||
for(i=0; i<n; i++)
|
||||
res += sum_array[i];
|
||||
|
||||
return res;
|
||||
}
|
||||
2
cs2106/labs/lab2/part1/autograder/subs/A0281754H/utils.h
Normal file
2
cs2106/labs/lab2/part1/autograder/subs/A0281754H/utils.h
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
int sum(int [], int);
|
||||
42
cs2106/labs/lab2/part1/autograder/subs/A0285757B/sum.c
Normal file
42
cs2106/labs/lab2/part1/autograder/subs/A0285757B/sum.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "utils.h"
|
||||
|
||||
#define MAX_STR_LEN 128
|
||||
|
||||
void strip(char *str) {
|
||||
while(*str) {
|
||||
if(*str == '\n')
|
||||
*str = '\0';
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
char str[MAX_STR_LEN];
|
||||
int nums[128];
|
||||
int count=0;
|
||||
int res = 0;
|
||||
|
||||
while(!feof(stdin)) {
|
||||
char *res = fgets(str, MAX_STR_LEN, stdin);
|
||||
|
||||
if(res){
|
||||
strip(str);
|
||||
int val = atoi(str);
|
||||
|
||||
if(val){
|
||||
nums[count++] = val;
|
||||
}
|
||||
else
|
||||
printf("%s is not a non-zero integer.\n", str);
|
||||
}
|
||||
}
|
||||
|
||||
res = sum(nums, count);
|
||||
printf("Item count is %d\n", count);
|
||||
printf("The sum is %d\n", res);
|
||||
exit(res);
|
||||
}
|
||||
|
||||
10
cs2106/labs/lab2/part1/autograder/subs/A0285757B/utils.c
Normal file
10
cs2106/labs/lab2/part1/autograder/subs/A0285757B/utils.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "utils.h"
|
||||
|
||||
int sum(int sum_array[], int n) {
|
||||
int i, res = 0;
|
||||
|
||||
for(i=0; i<n; i++)
|
||||
res += sum_array[i];
|
||||
|
||||
return res;
|
||||
}
|
||||
2
cs2106/labs/lab2/part1/autograder/subs/A0285757B/utils.h
Normal file
2
cs2106/labs/lab2/part1/autograder/subs/A0285757B/utils.h
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
double sum(int [], int);
|
||||
5
cs2106/labs/lab2/part1/diff.sh
Executable file
5
cs2106/labs/lab2/part1/diff.sh
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
x=15
|
||||
y=20
|
||||
z=$(($x-$y))
|
||||
echo "$x - $y = $z"
|
||||
2
cs2106/labs/lab2/part1/file.txt
Normal file
2
cs2106/labs/lab2/part1/file.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
This is a text file.
|
||||
CS2106 Introduction to Operating Systems is a cool module!
|
||||
3
cs2106/labs/lab2/part1/greet.sh
Executable file
3
cs2106/labs/lab2/part1/greet.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Hello $(whoami), today is $(date)"
|
||||
2
cs2106/labs/lab2/part1/hello.sh
Executable file
2
cs2106/labs/lab2/part1/hello.sh
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
echo "Hello World"
|
||||
29
cs2106/labs/lab2/part1/slow.c
Normal file
29
cs2106/labs/lab2/part1/slow.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
|
||||
// For the sleep functiopn
|
||||
#include <unistd.h>
|
||||
|
||||
// For the atoi function that converts
|
||||
// strings to integers
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int ac, char **av) {
|
||||
if(ac != 2) {
|
||||
printf("\nCounts from specified integer n to n + 5\n");
|
||||
printf("Usage: %s <integer>\n\n", av[0]);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
int n = atoi(av[1]);
|
||||
int i;
|
||||
for(i=n; i<=n+5; i++) {
|
||||
printf("%d\n", i);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
printf("\nFinal value of i is %d\n\n", i);
|
||||
|
||||
exit(i);
|
||||
}
|
||||
|
||||
|
||||
13
cs2106/labs/lab2/part1/talk.c
Normal file
13
cs2106/labs/lab2/part1/talk.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define BUF_SIZE 128
|
||||
|
||||
int main() {
|
||||
char input[128];
|
||||
char *ret;
|
||||
while(!feof(stdin)) {
|
||||
ret = fgets(input, BUF_SIZE - 1, stdin);
|
||||
if(ret != NULL)
|
||||
printf("This is what I read: %s\n", input);
|
||||
}
|
||||
}
|
||||
2
cs2106/labs/lab2/part2/file.txt
Normal file
2
cs2106/labs/lab2/part2/file.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
This is a text file.
|
||||
CS2106 Introduction to Operating Systems is a cool module!
|
||||
47
cs2106/labs/lab2/part2/lab2p2a.c
Normal file
47
cs2106/labs/lab2/part2/lab2p2a.c
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
int slow(char *name, int time, int n) {
|
||||
for(int i=n; i<=n+4; i++) {
|
||||
printf("%s: i = %d\n", name, i);
|
||||
sleep(time);
|
||||
}
|
||||
}
|
||||
|
||||
sdf
|
||||
asdf
|
||||
as
|
||||
dfas
|
||||
f
|
||||
|
||||
int main() {
|
||||
int id;
|
||||
|
||||
if((id = fork()) != 0) {
|
||||
int stat;
|
||||
int my_id = getpid();
|
||||
int parent_id = getppid();
|
||||
printf("\nI am the parent.\n");
|
||||
printf("My ID is %d\n", my_id);
|
||||
printf("My parent's ID is %d\n", parent_id);
|
||||
printf("My child's ID is %d\n\n", id);
|
||||
slow("Parent", 1, 5);
|
||||
printf("\nWaiting for child to exit.\n");
|
||||
wait(&stat);
|
||||
printf("CHILD HAS EXITED WITH STATUS %d\n", WEXITSTATUS(stat));
|
||||
}
|
||||
else
|
||||
{
|
||||
id = getpid();
|
||||
int parent_id = getppid();
|
||||
printf("\nI am the child.\n");
|
||||
printf("My ID is %d\n", id);
|
||||
printf("My parent's ID is %d\n\n", parent_id);
|
||||
slow("Child", 2, 10);
|
||||
exit(25);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
17
cs2106/labs/lab2/part2/lab2p2b.c
Normal file
17
cs2106/labs/lab2/part2/lab2p2b.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int ac, char **av, char **vp) {
|
||||
printf("ac = %d\n", ac);
|
||||
printf("Arguments:\n");
|
||||
|
||||
int i;
|
||||
|
||||
for(i=0; i<ac; i++)
|
||||
printf("Arg %d is %s\n", i, av[i]);
|
||||
|
||||
i=0;
|
||||
while(vp[i] != NULL) {
|
||||
printf("Env %d is %s\n", i, vp[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
12
cs2106/labs/lab2/part2/lab2p2c.c
Normal file
12
cs2106/labs/lab2/part2/lab2p2c.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
int main() {
|
||||
if(fork() == 0) {
|
||||
execlp("cat", "cat", "file.txt", NULL);
|
||||
}
|
||||
else
|
||||
wait(NULL);
|
||||
}
|
||||
|
||||
24
cs2106/labs/lab2/part2/lab2p2d.c
Normal file
24
cs2106/labs/lab2/part2/lab2p2d.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
int main() {
|
||||
int fp_in = open("./file.txt", O_RDONLY);
|
||||
int fp_out = open("./talk.out", O_CREAT | O_WRONLY);
|
||||
|
||||
if(fork() == 0) {
|
||||
dup2(fp_in, STDIN_FILENO);
|
||||
dup2(fp_out, STDOUT_FILENO);
|
||||
execlp("./talk", "talk", (char *) 0);
|
||||
close(fp_in);
|
||||
close(fp_out);
|
||||
}
|
||||
else
|
||||
wait(NULL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
34
cs2106/labs/lab2/part2/lab2p2e.c
Normal file
34
cs2106/labs/lab2/part2/lab2p2e.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
int main() {
|
||||
int p[2];
|
||||
char str[] = "Hello this is the parent.";
|
||||
|
||||
// This creates a pipe. p[0] is the reading end,
|
||||
// p[1] is the writing end.
|
||||
|
||||
if(pipe(p) < 0)
|
||||
perror("lab2p2e: ");
|
||||
|
||||
// We will send a message from father to child
|
||||
if(fork() != 0) {
|
||||
close(p[0]); // The the end we are not using.
|
||||
write(p[1], str, strlen(str));
|
||||
close(p[1]);
|
||||
wait(NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
char buffer[128];
|
||||
|
||||
close(p[1]); // Close the writing end
|
||||
read(p[0], buffer, 127);
|
||||
printf("Child got the message \"%s\"\n", buffer);
|
||||
close(p[0]);
|
||||
}
|
||||
}
|
||||
|
||||
20
cs2106/labs/lab2/part2/lab2p2f.c
Normal file
20
cs2106/labs/lab2/part2/lab2p2f.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/wait.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
int main() {
|
||||
|
||||
printf("Be patient, the program will take around 7 seconds to run.\n");
|
||||
printf("At the end you can do \"cat results.out\" to see the result.\n");
|
||||
|
||||
//
|
||||
// Add code here to pipe from ./slow 5 to ./talk and redirect
|
||||
// output of ./talk to results.out
|
||||
// I.e. your program should do the equivalent of ./slow 5 | talk > results.out
|
||||
// WITHOUT using | and > from the shell.
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
29
cs2106/labs/lab2/part2/slow.c
Normal file
29
cs2106/labs/lab2/part2/slow.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
|
||||
// For the sleep functiopn
|
||||
#include <unistd.h>
|
||||
|
||||
// For the atoi function that converts
|
||||
// strings to integers
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int ac, char **av) {
|
||||
if(ac != 2) {
|
||||
printf("\nCounts from specified integer n to n + 5\n");
|
||||
printf("Usage: %s <integer>\n\n", av[0]);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
int n = atoi(av[1]);
|
||||
int i;
|
||||
for(i=n; i<=n+5; i++) {
|
||||
printf("%d\n", i);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
printf("\nFinal value of i is %d\n\n", i);
|
||||
|
||||
exit(i);
|
||||
}
|
||||
|
||||
|
||||
13
cs2106/labs/lab2/part2/talk.c
Normal file
13
cs2106/labs/lab2/part2/talk.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define BUF_SIZE 128
|
||||
|
||||
int main() {
|
||||
char input[128];
|
||||
char *ret;
|
||||
while(!feof(stdin)) {
|
||||
ret = fgets(input, BUF_SIZE - 1, stdin);
|
||||
if(ret != NULL)
|
||||
printf("This is what I read: %s\n", input);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user