Professional Documents
Culture Documents
Exam Advanced Operating Systems
Exam Advanced Operating Systems
Lab Project
Answer:
Matrea Ahmed
ID201912758
1-
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
void print_odd_numbers(int number) {
printf("Odd numbers below %d:\n", number);
int i = 1;
while (i < number) {
printf("%d ", i);
i += 2;
}
printf("\n");
}
int main() {
int number;
print_odd_numbers(number);
return 0;
}
2-
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
pid_t child_pid = fork();
if (child_pid == -1) {
perror("Fork error");
exit(1);
} else if (child_pid == 0) {
printf("Child process - PID: %d\n", getpid());
} else {
wait(NULL);
printf("Parent process - PID: %d\n", getpid());
}
return 0;
}
3-
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *source_file, *destination_file;
char ch;
// Create the source file and write content
source_file = fopen("OSLAB.txt", "w");
if (source_file == NULL) {
printf("Error creating source file.\n");
exit(1);
}
fprintf(source_file, "First Name: Matrea\nLast Name: Ahmed\n");
fclose(source_file);
return 0;
0;
}