-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.c
44 lines (38 loc) · 880 Bytes
/
common.c
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
#define _GNU_SOURCE
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <sched.h>
#include "library/common.h"
#include "library/priority.h"
int nProcess;
int idProcess[MAX_PROCESS_NUM];
pid_t pid[MAX_PROCESS_NUM];
int ptr_Ready = 0;
int ptr_Run = 0;
int run = 0;
void unit_time()
{
volatile unsigned long i;
for (i = 0; i < TIME_UNIT; i++);
}
void create_process (pid_t *pid, char *N, int I, int T)
{
if ((*pid = fork()) < 0)
ERR_EXIT("Fork error!");
if (*pid == 0)
{
char execute_time[20], id[10];
sprintf(execute_time, "%u", T);
sprintf(id, "%u", I);
execl("./process", "./process", N, id, execute_time, (char *)0);
}
if (*pid > 0)
{
fflush(stderr);
SET_PRIORITY(*pid, SCHED_FIFO, PRIORITY_LOW);
CPU(*pid, 1);
}
}