Untitled
unknown
plain_text
a year ago
844 B
4
Indexable
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <time.h>
int i = 0;
int j = 0;
int n = 9;
int p = 0;
void perform_computation() {
for (i = 0; i < 100000000; i++) {
}
}
int main() {
// (SCHED_FIFO, SCHED_RR, SCHED_OTHER)
int algorithm = SCHED_FIFO;
for (j = 0; j < n; j++) {
pid_t child_pid = fork();
if (child_pid == 0) {
struct sched_param param;
param.sched_priority = 1;
if (sched_setscheduler(0, algorithm, ¶m) == -1) {
perror("sched_setscheduler");
exit(1);
}
printf("Proces potomny %d (PID: %d)\n", j, getpid(), param.sched_priority);
perform_computation();
exit(0);
}
}
return 0;
}
Editor is loading...
Leave a Comment