init commit
This commit is contained in:
Executable
+52
@@ -0,0 +1,52 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <wait.h>
|
||||
#include <errno.h>
|
||||
|
||||
void
|
||||
str_to_ll(char *str, long long *num)
|
||||
{
|
||||
errno = 0;
|
||||
char *endptr;
|
||||
*num = strtoll(str, &endptr, 10);
|
||||
|
||||
if (*endptr || errno || endptr == str) {
|
||||
fprintf(stderr, "Invalid number: %s\n", str);
|
||||
exit(1); // TODO: по-хорошему заменить на внешний обработчик ошибок
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
pid_t pid = fork();
|
||||
|
||||
if (pid == -1) {
|
||||
return 1;
|
||||
}
|
||||
if (pid == 0) {
|
||||
char buf[8] = {0};
|
||||
read(0, buf, 7);
|
||||
|
||||
// long long t;
|
||||
// str_to_ll(buf, &t);
|
||||
|
||||
int t = (int) strtol(buf, NULL, 10);
|
||||
|
||||
printf("%d\n", t * t);
|
||||
return 0;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
while (wait(NULL) != -1)
|
||||
;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <wait.h>
|
||||
#include <errno.h>
|
||||
|
||||
// 8-ми сегментная таблица сегментов
|
||||
// 32-х разрядная система
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int size;
|
||||
int base;
|
||||
} segment;
|
||||
|
||||
unsigned int
|
||||
f(segment *segtable, unsigned int VAdr)
|
||||
{
|
||||
int bit = 3;
|
||||
unsigned int segnum = VAdr >> (32 - bit);
|
||||
unsigned int segoff = VAdr & ((1 << (32 - bit)) - 1);
|
||||
|
||||
int addr = segtable[segnum].base + segoff;
|
||||
int size = segtable[segnum].size;
|
||||
|
||||
if (segoff >= size) {
|
||||
return 25;
|
||||
// exit(1);
|
||||
}
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
segment segtable[8] = {};
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <wait.h>
|
||||
#include <errno.h>
|
||||
|
||||
// инвертированная сегментная таблица сегментов
|
||||
// 32-х разрядная система
|
||||
|
||||
typedef struct
|
||||
{
|
||||
pid_t pid;
|
||||
unsigned int VirtNum;
|
||||
} page_record;
|
||||
|
||||
unsigned int
|
||||
f(page_record *pagetable, unsigned int VAdr, int size_segtable)
|
||||
{
|
||||
pid_t pid = getpid();
|
||||
|
||||
unsigned int pagenum = VAdr >> (12); // 12 - размер страницы
|
||||
|
||||
for (int i = 0; i < size_segtable; i++) {
|
||||
if (pagetable[i].VirtNum == pagenum && pagetable[i].pid == pid) {
|
||||
return i << (32 - 12) + (VAdr << 20 >> 20);
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
|
||||
// по номеру начального размер блока и указатель на таблицу файлов
|
||||
// вывести размер файла
|
||||
|
||||
unsigned int
|
||||
f(unsigned int n, unsigned int *table)
|
||||
{
|
||||
unsigned int size = 0;
|
||||
int first_block = table[n];
|
||||
while (first_block) {
|
||||
size++; // размер блока
|
||||
first_block = table[first_block];
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
000007
|
||||
000010
|
||||
000009
|
||||
Reference in New Issue
Block a user