Compare commits
No commits in common. "de423c103691a9392a365a543ece45d21e4587bc" and "1c58c428971c18fb5197842f9bd2bdc36a9a72b3" have entirely different histories.
de423c1036
...
1c58c42897
2 changed files with 1 additions and 88 deletions
|
|
@ -13,7 +13,6 @@ page_for: "sp1-lesson"
|
||||||
- `mkrepo` zum Aufgaben-Repo erstellen
|
- `mkrepo` zum Aufgaben-Repo erstellen
|
||||||
- `deadline` zum Abgabetermine nachschauen
|
- `deadline` zum Abgabetermine nachschauen
|
||||||
- Vorgegebene Compiler-Flags: `-std=c11` `-pedantic` `-D_XOPEN_SOURCE=700` `-Wall` `-Werror` `-fsanitize=undefined` `-fno-sanitize-recover` `-g`
|
- Vorgegebene Compiler-Flags: `-std=c11` `-pedantic` `-D_XOPEN_SOURCE=700` `-Wall` `-Werror` `-fsanitize=undefined` `-fno-sanitize-recover` `-g`
|
||||||
- Debugger Valgrind kann so ausgeführt werden: `valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./--track-fds=yes ./lilo`
|
|
||||||
|
|
||||||
## Wichtige Links
|
## Wichtige Links
|
||||||
- [Aufgaben](https://sys.cs.fau.de/lehre/ss25/sp1/uebung#aufgaben)
|
- [Aufgaben](https://sys.cs.fau.de/lehre/ss25/sp1/uebung#aufgaben)
|
||||||
|
|
@ -41,4 +40,4 @@ page_for: "sp1-lesson"
|
||||||
- [Lukas (T03)](https://wwwcip.cs.fau.de/~uk16isyq/)
|
- [Lukas (T03)](https://wwwcip.cs.fau.de/~uk16isyq/)
|
||||||
- [Julian (T08)](https://jzbor.de/tut/sp1/)
|
- [Julian (T08)](https://jzbor.de/tut/sp1/)
|
||||||
- [Luca (T11)](https://wwwcip.cs.fau.de/~am99ihig/sp)
|
- [Luca (T11)](https://wwwcip.cs.fau.de/~am99ihig/sp)
|
||||||
- [Philip (ehemalig)](https://wwwcip.cs.fau.de/~oj14ozun/sp1/) (Hier ist das sp-quiz!)
|
- [Philip (ehemalig)](https://wwwcip.cs.fau.de/~oj14ozun/sp1/)
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
---
|
|
||||||
title: "Übung 03 - Prozesse"
|
|
||||||
layout: "blog-post.njk"
|
|
||||||
tags: "sp1-lesson"
|
|
||||||
date: 2025-05-19
|
|
||||||
---
|
|
||||||
### waitpid()
|
|
||||||
Mit `waitpid()` können Informationen über den Exitstatus eines Kindprozesses abgefragt werden.
|
|
||||||
By default wartet waitpid, bis das angegebene Kind terminiert. Falls das nicht gewünscht ist, kann options=WNOHANG als Argument von waitpid() angegeben werden.
|
|
||||||
|
|
||||||
|
|
||||||
## Beispiel Programme aus der Präsenzübung
|
|
||||||
### `listRun.c`: Übergebenes Programm mehrfach mit verschiedenen Argumenten aufrufen
|
|
||||||
```c
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
if (argc < 3) {
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *command = argv[1];
|
|
||||||
|
|
||||||
for (int i = 2; i < argc; i++) {
|
|
||||||
pid_t pid = fork();
|
|
||||||
if (pid == -1) {
|
|
||||||
// Fehler
|
|
||||||
perror("fork");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
} else if (pid == 0) {
|
|
||||||
// Child
|
|
||||||
if (execlp(command, command, argv[i], NULL) == -1) {
|
|
||||||
perror("execlp");
|
|
||||||
}
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
} else {
|
|
||||||
// Parent (pid == child's pid)
|
|
||||||
int status;
|
|
||||||
waitpid(pid, &status, 0);
|
|
||||||
// ... waitpid Fehlerbehandlung
|
|
||||||
if (WIFEXITED(status)) {
|
|
||||||
fprintf(stderr, "Exitstatus: %d\n", WEXITSTATUS(status));
|
|
||||||
// ... fprintf Fehlerbehandlung
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Makefile für `listRun.c`
|
|
||||||
```Makefile
|
|
||||||
CC=gcc
|
|
||||||
CFLAGS=-std=c11 -pedantic -Wall -Werror -fsanitize=undefined -fno-sanitize-recover -g -D_XOPEN_SOURCE=700
|
|
||||||
|
|
||||||
all: listRun
|
|
||||||
|
|
||||||
listRun: listRun.o
|
|
||||||
$(CC) $(CFLAGS) -o listRun listRun.o
|
|
||||||
|
|
||||||
listRun.o: listRun.c
|
|
||||||
$(CC) $(CFLAGS) -o listRun.o -c listRun.c
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -rf listRun listRun.o
|
|
||||||
|
|
||||||
.PHONY: all clean
|
|
||||||
```
|
|
||||||
|
|
||||||
### strtok-test
|
|
||||||
```c
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
char str[] = "hello world"; // auf dem stack, damit schreibbar
|
|
||||||
char *token;
|
|
||||||
token = strtok(str, " ");
|
|
||||||
while (token != NULL) {
|
|
||||||
printf("%s\n", token);
|
|
||||||
token = strtok(NULL, " ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
Loading…
Add table
Reference in a new issue