-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSharedProcess.h
More file actions
53 lines (45 loc) · 2.18 KB
/
Copy pathSharedProcess.h
File metadata and controls
53 lines (45 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
File name: SharedProcess.h
Author: Marcel Riera
Description: Header file containing libraries, constants and
function prototypes required for the program.
Requirements: The following files must be in the same folder for
proper compilation:
- SharedMain.c
- SharedChild.c
- SharedProcess.h
*/
/* Included libraries */
#include <stdio.h> // Required for input and output
#include <stdlib.h> // Required for validation (atoi)
#include <string.h> // Required for validation (strcmp, strcat)
#include <unistd.h> // Required for fork
#include <sys/shm.h> // Required for shared memory
#include <sys/wait.h> // Required for wait() function
/* Declared constants */
#define MIN_ARGUMENTS 2 // Minimum amount of arguments expected
#define MAX_ARGUMENTS 8 // Maximum amount of arguments expected
#define FIRST_ARGUMENT 1 // First argument, disregarding path arg
#define ARG_MIN_VALUE 0 // Minimum value for a given argument
#define ARG_MAX_VALUE 9 // Maximum value for a given argument
#define INVALID_ARGUMENTS -1 // Return code for invalid arguments
#define NO_ERRORS 0 // Return code for exit succesful
#define FAILED -1 // Return code for exit failed
#define INDEX_OFFSET 1 // Offset to compensate for array index 0
#define TRUE 1 // True for boolean expressions
#define FALSE 0 // False for boolean expressions
#define SHM_PROTOCOL 0666 // Protocol required for shared memory
#define FORK_CHILD 0 // Fork ID return for a child process
#define BUFFER_SIZE 32 // Arbitrary buffer size for strings
#define TAB_SIZE 2 // Indentation spaces for trace displays
static const char* ORDER[] = {"", "first", "second", "third", "fourth",
"fifth", "sixth", "seventh"};
/* Function prototypes */
int validateCommandLine(int argc, char* argv[]);
int isUnique(int toTest, int arrayToTest[], int index);
char* toString(int arrayToDisplay[], int size);
void fillSharedMemory(int sharedMemory[], int argc, char* argv[]);
int parentForkChildProcesses(int parentPID, int childAmount, int* childID);
void parentWaitAllChildren(int argc);
int childMain(int childID, int* sharedMemory, const int size);
char* getPrefix(int childID);