Du befindest dich hier: FSI Informatik » jahrgaenge » 2006 » "Muster"-Lösungen » "Muster"-Lösungen zu Klausuren aus Softwaresysteme 1 » Vordiplomsklausuren » März 2005
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
Beide Seiten, vorherige ÜberarbeitungVorherige ÜberarbeitungNächste Überarbeitung | Vorherige Überarbeitung | ||
jahrgaenge:2006:loesungen:softwaresysteme_1:vordiplom:mar2005 [05.09.2007 09:46] – 131.188.30.85 | jahrgaenge:2006:loesungen:softwaresysteme_1:vordiplom:mar2005 [08.09.2007 19:17] (aktuell) – 89.58.27.191 | ||
---|---|---|---|
Zeile 9: | Zeile 9: | ||
* e) 1 | * e) 1 | ||
* f) 1(?) das ist mal ne wirklich interessante frage... | * f) 1(?) das ist mal ne wirklich interessante frage... | ||
- | -> Wenn keine Verdrängung stattfindet und zu einem Zeitpunkt nur ein Prozeß laufen kann, weil nur ein Prozessor da ist, kommt keine Nebenläufigkeit zustande. Also müssen die Zugriffe nicht koordiniert werden. | + | -> Wenn zu einem Zeitpunkt nur ein Prozeß |
* g) 3 | * g) 3 | ||
* h) 2 | * h) 2 | ||
* i) 4 | * i) 4 | ||
- | * j) 4 //(?) ich tippe auf 2: eine seite = 4096, hauptspeicher = 4GB => ca. 2000 seiten im system, jeder eintrag in der tabelle 4 byte (32bit) macht dann 2000 x 4 = 8000 byte...// 4 ist korrekt, Rechnung: 4294967296 / 4096 *32 / 8 = 4194304 //Ich will nen TR!// | + | * j) 4 //(?) ich tippe auf 2: eine seite = 4096, hauptspeicher = 4GB => ca. 2000 seiten im system, jeder eintrag in der tabelle 4 byte (32bit) macht dann 2000 x 4 = 8000 byte...// |
* k) 3 | * k) 3 | ||
* l) 2 | * l) 2 | ||
Zeile 71: | Zeile 71: | ||
port = atoi(argv[1]); | port = atoi(argv[1]); | ||
- | /* Ein Signal-Handler für SIGCHLD (ein Kindprozess stirbt) wird installiert. So können Zombies mit waitpid abgeholt werden. | + | /* Ein Signal-Handler für SIGCHLD (ein Kindprozess stirbt) wird installiert. So können Zombies mit waitpid abgeholt werden. */ |
action.sa_handler = sighandler; | action.sa_handler = sighandler; | ||
sigemtpyset(& | sigemtpyset(& | ||
Zeile 186: | Zeile 186: | ||
} | } | ||
+ | </ | ||
+ | |||
+ | Alternative Lösung: Diese schreibt die angeforderte Information auch wieder auf den socket zurück | ||
+ | |||
+ | <code c> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | /* fehlende includes */ | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | #define DEFAULT_PORT 31337 | ||
+ | |||
+ | static void serve(int socket); | ||
+ | static void prattr(char *filename); | ||
+ | static void sigchld_handler_install(void); | ||
+ | static void sigchld_handler(int sig); | ||
+ | |||
+ | int main(int argc, char *argv[]) { | ||
+ | int sock; | ||
+ | unsigned short port; | ||
+ | struct sockaddr_in saddr; | ||
+ | |||
+ | if (argc > 1) { | ||
+ | port = atoi(argv[1]); | ||
+ | } else { | ||
+ | port = DEFAULT_PORT; | ||
+ | } | ||
+ | |||
+ | sigchld_handler_install(); | ||
+ | |||
+ | sock = socket(PF_INET, | ||
+ | if (sock < 0) { | ||
+ | perror(" | ||
+ | return EXIT_FAILURE; | ||
+ | } | ||
+ | | ||
+ | saddr.sin_family = AF_INET; | ||
+ | saddr.sin_addr.s_addr = htonl(INADDR_ANY); | ||
+ | saddr.sin_port = htons(port); | ||
+ | |||
+ | if (bind(sock, (struct sockaddr *) &saddr, sizeof(saddr)) == -1) { | ||
+ | perror(" | ||
+ | return EXIT_FAILURE; | ||
+ | } | ||
+ | |||
+ | if (listen(sock, | ||
+ | perror(" | ||
+ | return EXIT_FAILURE; | ||
+ | } | ||
+ | | ||
+ | printf(" | ||
+ | | ||
+ | while (1) { | ||
+ | pid_t pid; | ||
+ | int clsock; | ||
+ | struct sockaddr clsaddr; | ||
+ | socklen_t clsaddr_len = sizeof(clsaddr); | ||
+ | |||
+ | clsock = accept(sock, | ||
+ | if (clsock == -1) { | ||
+ | perror(" | ||
+ | continue; | ||
+ | } | ||
+ | |||
+ | switch(pid = fork()) { | ||
+ | case -1: | ||
+ | /* error */ | ||
+ | perror(" | ||
+ | return EXIT_FAILURE; | ||
+ | |||
+ | break; | ||
+ | case 0: | ||
+ | /* child */ | ||
+ | close(sock); | ||
+ | |||
+ | serve(clsock); | ||
+ | |||
+ | close(clsock); | ||
+ | exit(EXIT_SUCCESS); | ||
+ | |||
+ | break; | ||
+ | case 1: | ||
+ | /* parent */ | ||
+ | close(clsock); | ||
+ | |||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | return EXIT_SUCCESS; | ||
+ | } | ||
+ | |||
+ | static void serve(int socket) { | ||
+ | char file[128+2]; | ||
+ | FILE *fd = fdopen(socket, | ||
+ | |||
+ | if (dup2(socket, | ||
+ | perror(" | ||
+ | exit(EXIT_FAILURE); | ||
+ | } | ||
+ | |||
+ | while(fgets(file, | ||
+ | file[strlen(file)-1] = ' | ||
+ | |||
+ | prattr(file); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | static void prattr(char *filename) { | ||
+ | struct stat statbuf; | ||
+ | |||
+ | if (stat(filename, | ||
+ | printf(" | ||
+ | } else { | ||
+ | if (S_ISDIR(statbuf.st_mode)) { | ||
+ | printf(" | ||
+ | } else if (S_ISREG(statbuf.st_mode)) { | ||
+ | printf(" | ||
+ | } else { | ||
+ | printf(" | ||
+ | } | ||
+ | } | ||
+ | fclose(fd); | ||
+ | } | ||
+ | |||
+ | static void sigchld_handler_install(void) { | ||
+ | struct sigaction sa; | ||
+ | | ||
+ | sigemptyset(& | ||
+ | sa.sa_handler = sigchld_handler; | ||
+ | sa.sa_flags = SA_RESTART | SA_NOCLDSTOP; | ||
+ | if (sigaction(SIGCHLD, | ||
+ | perror(" | ||
+ | exit(EXIT_FAILURE); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | static void sigchld_handler(int sig) { | ||
+ | int errsvr; | ||
+ | int status; | ||
+ | pid_t pid; | ||
+ | |||
+ | errsvr = errno; | ||
+ | |||
+ | while((pid = waitpid(-1, & | ||
+ | if (pid == -1) { | ||
+ | if (errno == ECHILD) { | ||
+ | break; | ||
+ | } | ||
+ | perror(" | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | errno = errsvr; | ||
+ | } | ||
</ | </ | ||
Zeile 191: | Zeile 358: | ||
< | < | ||
- | fileattrd: fileattrd.c | + | fileattrd: fileattrd.o |
- | gcc -o fileattrd fileattrd.c | + | |
- | .PHONY | + | .PHONY: clean |
clean: | clean: | ||
- | rm -rf fileattrd | + | $(RM) fileattrd |
+ | |||
+ | #restliche regeln sind alle implizit vorhanden | ||
</ | </ |