Skip to content
Snippets Groups Projects
T1.c 968 B
Newer Older
antux18's avatar
antux18 committed
#include<stdio.h>
#include<sys/mman.h>
#include<stdlib.h>
#include<fcntl.h>
#include<unistd.h>
#include<sys/wait.h>
#include<string.h>

#define SIZE 10000
#define SCRATCH_FILE "./shared-file"

void swap(int *xp, int *yp);
void sort(int arr[], int size);

int main() {
    int arr[SIZE];
    for(int i = SIZE - 1; i >= 0; i--)
        arr[(SIZE - 1) - i] = i % 2;

    // TODO: Fork another process here
    // TODO: One process should calculate the median
    // TODO: The other process should calculate the mean
    // TODO: Use shm_open, ftruncate, mmap, and munmap to communicate over mapped files
    // TODO: Print both calculated results and involved PIDs
    
    return 0;
}

void swap(int *xp, int *yp) {
    int temp = *xp;
    *xp = *yp;
    *yp = temp;
}

void sort(int *arr, int size) {
    for (int i = 0; i < size - 1; i++)
        for (int j = 0; j < size - i - 1; j++)
            if (arr[j] > arr[j + 1])
                swap(&arr[j], &arr[j + 1]);
}