Download presentation
Presentation is loading. Please wait.
Published byAndrew Rollins Modified over 11 years ago
1
Institut für Angewandte Mikroelektronik und Datentechnik Fachbereich Elektrotechnik und Informationstechnik, Universität Rostock Vorlesung Echtzeitbetriebssysteme V. Interprozesskoordination Dr.-Ing. Frank Golatowski
2
Institut MD Universität Rostock Ziele der Vorlesung
3
Institut MD Universität Rostock Scheduling SCHED_FIFO SCHED_RR SCHED_OTHER
4
Institut MD Universität Rostock Scheduling sched_setscheduler (pid, policy, param) sched_setparam (pid,param) int sched_get_priority_min (policy) in Linux 1 int sched_get_priority_max (policy) in Linux 99 sched_yield(void) #include struct sched_param param; main(){ printf("RR min: %ld\n",sched_get_priority_min(SCHED_RR)); printf("RR max: %ld\n",sched_get_priority_max(SCHED_RR)); printf("FIFO min: %ld\n",sched_get_priority_min(SCHED_FIFO)); printf("FIFO max: %ld\n",sched_get_priority_max(SCHED_FIFO)); param.sched_priority = 10; fork(); sched_setscheduler(0,SCHED_FIFO, ¶m); tue_etwas(); }
5
Institut MD Universität Rostock Memlock mlock (address, length) munlock (address, length) mlockall (flags) munlockall (void) #include main(){ mlock(MCL_CURRENT|MCL_FUTURE); /* */ tue_etwas(); }
6
Institut MD Universität Rostock Shared memory void *mmap ( start, len, prot, flags, fd, offset) munmap (start,len) #include main(){ fd = open ("kk.ps",O_RDWR); ptr = mmap(NULL, 100*sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED,fd,0L); } ptr[0]=0; if (fork()==0) { /* Sohn */ while (ptr[0]==0); } else { /* Vater */ ptr[0]=1; }
7
Institut MD Universität Rostock Synchronisation sem_id sem_open (name, oflags, mode, init_value) sem_close (sem_id) sem_unlink (number)
8
Institut MD Universität Rostock Semaphore sem_wait (sem_id) sem_post (sem_id) sem_trywait (sem_id) int sem_get_value (sem_id) #include main(){ sem_t *mutex; int x; mutex=sem_open("SEMA",O_CREAT,0,1); if (fork() == 0) { printf("Sohn startet" %d\n",x); sem_wait(mutex); printf("Sohn wird beendet\n"); } else { sleep(2); printf("Vater erwacht\n"); sem_post(mutex); printf("Vater wird beendet"\n"); }
9
Institut MD Universität Rostock Signale SIGILL SIGSEGV SIGTERM SIGALRM SIGKILL SIGFPE SIGSTOP, SIGCONT SIGUSR1, SIGUSR2 SIGRTMIN...SIGRTMAX
10
Institut MD Universität Rostock Signal Handling int sigaction (int signal, const struct sigaction *act, struct sigaction *oact); int kill (pid_t pid, int sig); int sigprocmask(int how, const sigset_t *set, sigset_t *oset); int sigsuspend(const sigset_t *set); struct sigaction { void (*sa_handler)(); sigset_t sa_mask; int sa_flags; void (*sa_sigaction)(...); }; SIG_BLOCK SIG_UNBLOCK SIG_SETMASK sigemptyset(*s) sigfillset(*s) sigaddset(*s,n) sigdelset(*s,n) sigismember(*s,n)
11
Institut MD Universität Rostock Signal Beispiel #include void handler (int senyal){ printf("an arithmetical exception has taken place\n"); } main(){ struct sigaction man; float a,b; int x; man.sa_flags = 0; man.sa_handler = handler; sigemptyset(&man.sa_mask); sigaction(SIGFPE, &man, NULL); for (x=0 ; x<100 ; x++) b = a / 0; printf("I am going to finalize\n"); }
12
Institut MD Universität Rostock Echtzeitsignale
13
Institut MD Universität Rostock Messagequeues mq_open mq_close mq_unlink mq_send mq_receive mq_setattr
14
Institut MD Universität Rostock Uhr (Clock) clock_gettime clock_getres nanosleep #include main(){ struct timespec B,A; clock_gettime(CLOCK_REALTIME,&A); clock_gettime(CLOCK_REALTIME,&B); printf("Two consecutive calls: %ld nseg\n", 1000000000L*(B.tv_sec-A.tv_sec)+(B.tv_nsec- A.tv_nsec)); }
15
Institut MD Universität Rostock Timer timer_create (clock_id, sig_spec, timer_new) timer_settimer (timer_id, flags, new_interval, old_interval) timer_gettimer (timer_id, current_interval) timer_delete (timer_id) struct itimerspec { struct timerspec it_value; struct timespec it_interval; };
16
Institut MD Universität Rostock Timer #include void handler (){ struct timespec ahora; signal(SIGRTMIN,manejador); clock_gettime(CLOCK_REALTIME,&ahora); printf("Instante => seg: %ld, nseg: %ld\n", ahora.tv_sec, ahorai.tv_nsec); } main(){ struct timespec B; struct itimerspec tempor_spec; timer_t tempor; struct sigevent evento; signal (SIGRTMIN,handler); evento.sigev_signo = SIGRTMIN; evento.sigev_notify = SIGEV_SIGNAL; timer_create(CLOCK_REALTIME, &evento,&tempor)); tempor_spec.it_value.tv_sec = 5; tempor_spec.it_value.tv_nsec = 0; tempor_spec.it_interval.tv_sec = 1; tempor_spec.it_interval.tv_nsec = 0; timer_settime(tempor, 0, &tempor_spec, NULL); clock_gettime(CLOCK_REALTIME,&B); printf("Instante => seg: %ld, nseg:%ld\n", B.tv_sec, B.tv_nsec); while (1) { sleep(100); } Noch nicht fertig
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.