Skip to content

Commit 5c61a05

Browse files
committed
updated report.md & change all 'processor' to 'process'
1 parent 863cc55 commit 5c61a05

File tree

8 files changed

+149
-131
lines changed

8 files changed

+149
-131
lines changed

README

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@
2525
* TA : Scott Kristjanson
2626

2727
## Description
28-
This program aims to decrypt large numbers of encrypted tweets, to speed up and take advantages of multiple CPU cores, we use fork function to spread the decryption task across multiple processes and use pipes to pass messages between the parent processor and child processors with two different scheduling algorithm "round robin" and "first come first serve".
28+
This program aims to decrypt large numbers of encrypted tweets, to speed up and take advantages of multiple CPU cores, we use fork function to spread the decryption task across multiple processes and use pipes to pass messages between the parent process and child processes with two different scheduling algorithm "round robin" and "first come first serve".
2929
Same as before, each tweet’s decryption follow four steps below:
3030
1. Remove unnecessary characters in regular interval.
3131
2. Transform each group of 6 characters into an integer using base 41.
3232
3. Map each cipher number onto a similar plain-text number.
3333
4. Get the final decrypted text by use the inverse function of Step 2.
34-
More Details can be found in [Assignment 2 - Process Management](https://courses.cs.sfu.ca/2015fa-cmpt-300-d1/pages/AssignmentThree/view)
34+
More Details can be found in [Assignment 3 - Message Passing & Scheduling](https://courses.cs.sfu.ca/2015fa-cmpt-300-d1/pages/AssignmentThree/view)
3535

3636
## Project Structure
3737
* "lyrebird.c" : contains the main loop function which using fork function to create child processes to do the decryption for each tweet file.
3838
* "decrypt.c" : contains a decrypt function, which go through 4 steps and in each step it call some functions in dec_func.c to handle decryption.
3939
* "dec_func.c" : contains many functions that used to decrypt the tweet, like remove extra characters, mapping characters to integer value and mapping integer to characters.
4040
* "pipe.c" : contains many functions that related to pipe including initialize pipe, close pipe and select pipe.
41-
* "scheduling.c" : contains two functions, each contains a scheduing algorithm that used to assign tasks to child processors in parent processor.
41+
* "scheduling.c" : contains two functions, each contains a scheduling algorithm that used to assign tasks to child processes in parent process.
4242
* "line_io.c" : contains two functions, input one line data from file and output one line data to file
4343
* "memwatch.c" : mainly used for detecting un-freed memory, overflow and underflow to memory buffers.
4444

@@ -54,12 +54,12 @@ More Details can be found in [Assignment 2 - Process Management](https://courses
5454
* Check whether the input and output file exist or not.
5555
* Check whether the tweet is multiple of 6 after removing extra characters.
5656
* Dynamic manage memory and guarantee to free all when program finished (also checked malloc function to see if it failed).
57-
* Parent process wait until all his child processers finished before exit.
58-
* Close all pipes that do not need in each processors.
57+
* Parent process wait until all his child processes finished before exit.
58+
* Close all pipes that do not need in each processes.
5959
* Empty data and largest data tested (used data set from assignment #2).
6060

6161
## Reference list
6262
[Select function - Linux man page](http://linux.die.net/man/2/select)
6363
[Multiple pipes and forks example](http://www.sfu.ca/~reilande/)
6464
[C using select() to read from two named pipes (FIFO) - Stackoverflow](http://stackoverflow.com/questions/28519119/c-using-select-to-read-from-two-named-pipes-fifo)
65-
[Set up arguments each time when using select function - Stackouverflow](http://stackoverflow.com/questions/3324078/why-select-always-return-0-after-the-first-timeout)
65+
[Set up arguments each time when using select function - Stackoverflow](http://stackoverflow.com/questions/3324078/why-select-always-return-0-after-the-first-timeout)

decrypt.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ char *decrypt_each(char *tweets_enc) {
7474
tweets_dec = (char *)malloc(sizeof(char) * TWEETS_MAX_LENGTH);
7575
if (tweets_dec == NULL) { /* Failed on malloc */
7676
get_tweets_time(); /* Print error message in child process */
77-
printf("[%s] (Processor ID #%d) ERROR: Malloc tweets_dec failed!\n", tweets_time, getpid());
77+
printf("[%s] (Process ID #%d) ERROR: Malloc tweets_dec failed!\n", tweets_time, getpid());
7878
flag = 1;
7979
return tweets_dec;
8080
}
@@ -84,7 +84,7 @@ char *decrypt_each(char *tweets_enc) {
8484

8585
if (len % CONSTANT_MULTIPLE != 0) { /* Check if len is multiple of 6 */
8686
get_tweets_time(); /* Print error message in child process */
87-
printf("[%s] (Processor ID #%d) ERROR: There is a tweet that is not multiple of 6!\n", tweets_time, getpid());
87+
printf("[%s] (Process ID #%d) ERROR: There is a tweet that is not multiple of 6!\n", tweets_time, getpid());
8888
flag = 0;
8989
return tweets_dec;
9090
}
@@ -94,7 +94,7 @@ char *decrypt_each(char *tweets_enc) {
9494
cipher_number = (unsigned long long *)malloc(sizeof(unsigned long long) * num_len);
9595
if (cipher_number == NULL) { /* Failed on malloc */
9696
get_tweets_time(); /* Print error message in child process */
97-
printf("[%s] (Processor ID #%d) ERROR: Malloc cipher_number failed!\n", tweets_time, getpid());
97+
printf("[%s] (Process ID #%d) ERROR: Malloc cipher_number failed!\n", tweets_time, getpid());
9898
flag = 1;
9999
return tweets_dec;
100100
}
@@ -107,7 +107,7 @@ char *decrypt_each(char *tweets_enc) {
107107
ptext_number = (unsigned long long *)malloc(sizeof(unsigned long long) * num_len);
108108
if (ptext_number == NULL) { /* Failed on malloc */
109109
get_tweets_time(); /* Print error message in child process */
110-
printf("[%s] (Processor ID #%d) ERROR: Malloc ptext_number failed!\n", tweets_time, getpid());
110+
printf("[%s] (Process ID #%d) ERROR: Malloc ptext_number failed!\n", tweets_time, getpid());
111111
flag = 1;
112112
return tweets_dec;
113113
}
@@ -120,7 +120,7 @@ char *decrypt_each(char *tweets_enc) {
120120
group_char = (char *)malloc(sizeof(char) * CONSTANT_MULTIPLE);
121121
if (group_char == NULL) { /* Failed on malloc */
122122
get_tweets_time(); /* Print error message in child process */
123-
printf("[%s] (Processor ID #%d) ERROR: Malloc group_char failed!\n", tweets_time, getpid());
123+
printf("[%s] (Process ID #%d) ERROR: Malloc group_char failed!\n", tweets_time, getpid());
124124
flag = 1;
125125
return tweets_dec;
126126
}
@@ -156,25 +156,25 @@ int decrypt(char *input, char *output) {
156156
FILE *fin, *fout;
157157

158158
tweets_time = (char *)malloc(sizeof(char) * TIME_MAXLENGTH);
159-
if (tweets_time == NULL) { /* If malloc time string failed, can't output time anymore... */
160-
printf("[XXX XXX 00 00:00:00 2015] (Processor ID #%d) ERROR: Malloc tweets_time failed!!!(Can't output time)\n", getpid());
159+
if (tweets_time == NULL) { /* If malloc time string failed, can't output time anymore... */
160+
printf("[XXX XXX 00 00:00:00 2015] (Process ID #%d) ERROR: Malloc tweets_time failed!!!(Can't output time)\n", getpid());
161161
return 0;
162162
}
163163

164164
fin = fopen(input, "r");
165165

166-
if (fin == NULL) { /* Check input file is exist or not */
167-
get_tweets_time(); /* Print error message in child process */
168-
printf("[%s] (Processor ID #%d) ERROR: Input file %s not exist!\n", tweets_time, getpid(), input);
166+
if (fin == NULL) { /* Check input file is exist or not */
167+
get_tweets_time(); /* Print error message in child process */
168+
printf("[%s] (Process ID #%d) ERROR: Input file %s not exist!\n", tweets_time, getpid(), input);
169169
free(tweets_time);
170170
return 0;
171171
}
172172

173173
fout = fopen(output, "w+");
174174

175-
if (fout == NULL) { /* Check if output file opened successfully */
176-
get_tweets_time(); /* Print error message in child process */
177-
printf("[%s] (Processor ID #%d) ERROR: Create output file %s failed!\n", tweets_time, getpid(), input);
175+
if (fout == NULL) { /* Check if output file opened successfully */
176+
get_tweets_time(); /* Print error message in child process */
177+
printf("[%s] (Process ID #%d) ERROR: Create output file %s failed!\n", tweets_time, getpid(), input);
178178
free(tweets_time);
179179
fclose(fin);
180180
return 0;
@@ -184,7 +184,7 @@ int decrypt(char *input, char *output) {
184184
tweets_enc = input_line(fin, &len); /* Get each line's tweet from input file */
185185
if (tweets_enc == NULL) {
186186
get_tweets_time(); /* Print error message in child process */
187-
printf("[%s] (Processor ID #%d) ERROR: Malloc tweets_enc string failed!\n", tweets_time, getpid());
187+
printf("[%s] (Process ID #%d) ERROR: Malloc tweets_enc string failed!\n", tweets_time, getpid());
188188
free(tweets_time);
189189
fclose(fin);
190190
return 0;

0 commit comments

Comments
 (0)