Betriebssysteme

Das Praktikum umfasst hauptsächlich die Handhabung von einigen kleinen Linux-Programmen zur Dateisystemverwaltung.

Z.T. sollte man einige Funktionen selber implementieren.

Beteiligt an dem Praktikum sind folgende Personen:

Dateisysteme

Aufgabenstellung teilweise ausgefüllt.

crea1.c

char buffer[] = "Krause Alexander, Hoeppler Thomas\n";
main ()
{
  int ufd_nr;
  int wbytes;
 
  ufd_nr=creat("Datei2",0700);
 
  wbytes=write(ufd_nr,buffer,strlen(buffer));
  close(ufd_nr);
}

open1.c

main ()
{
  int ufd_nr; /* User-File-Deskriptor */
  int rbytes; /* Anzahl gelesene Bytes */
  char buffer[100];
  ufd_nr = open("Datei1",0);
 
  rbytes = read(ufd_nr, buffer, 100);
  printf("Inhalt:\n\n%100s", buffer);
 
  close(ufd_nr);
}

lseek1.c

main ()
{
  int ufd_nr; /* User-File-Deskriptor */
  int rbytes; /* Anzahl gelesene Bytes */
  char buffer[100];
  int position;
 
  udf_nr = open("Datei1",0);
 
  position = lseek(ufd_nr,-100,2);
 
  rbytes = read(ufd_nr, buffer, 100);
  printf("Inhalt:\n\n%100s", buffer);
 
  close(ufd_nr);
}

bs2.c

main ()
{
  int ufd_nr; /* User-File-Deskriptor */
  int rbytes; /* Anzahl gelesene Bytes */
  char buffer[2000];
  ufd_nr = open("Datei1",0);
 
  rbytes = read(ufd_nr, buffer, 2000);
  printf("Inhalt:\n\n%2000s", buffer);
 
  close(ufd_nr);
}

bs3.c

main ()
{
  int ufd_nr; /* User-File-Deskriptor */
  int rbytes; /* Anzahl gelesene Bytes */
  char buffer[2000];
  ufd_nr = open("Datei1",0);
 
  rbytes = read(ufd_nr, buffer, 2000);
  if (rbytes==-1) printf("Datei konnte nicht geladen werden\n"); else
     printf("Inhalt:\n\n%2000s", buffer);
  close(ufd_nr);
}

bs4.c

main ()
{
  int ufd_nr; /* User-File-Deskriptor */
  int rbytes; /* Anzahl gelesene Bytes */
  char buffer[2000];
  ufd_nr = open("Datei1",0);
  printf("ufd_nr=%i\n",ufd_nr);
  rbytes = read(ufd_nr, buffer, 2000);
  if (rbytes==-1) printf("Datei konnte nicht geladen werden\n"); else
     printf("Inhalt:\n\n%2000s", buffer);
  close(ufd_nr);
}

bs5.c

char buffer[] = "Krause Alexander, Hoeppler Thomas\n";
main () {
  int ufd_nr;
  int wbytes;
  ufd_nr=creat("MeineDatei", 0664);
  wbytes=write(ufd_nr,buffer,strlen(buffer));
  close(ufd_nr);
}

bs6.c

main () {
  int cufd_nr;
  int rufd_nr;
  int rbytes;
  char buffer[100];
 
  cufd_nr=creat("tmp",0664);
 
  rufd_nr = open("tmp",0);
  rbytes = read(rufd_nr, buffer, 100);
  if (rbytes==-1) printf("Datei konnte nicht geladen werden\n"); else
     printf("Inhalt:\n\n%2000s", buffer);
  close(rufd_nr);
 
  close(cufd_nr);
}

bs7.c

main () {
  int ufd_nr; /* User-File-Deskriptor */
  int rbytes; /* Anzahl gelesene Bytes */
  char buffer[20];
  int position;
 
  ufd_nr = open("lseek1.c",0);
 
  position = lseek(ufd_nr,10,0);
  rbytes = read(ufd_nr, buffer, 20);
  printf("Inhalt:\n\n%20s", buffer);
 
  close(ufd_nr);
}

bs9.c

char buffer[] = "Krause Alexander, Hoeppler Thomas\n";
main () {
  int ufd_nr;
  int wbytes;
  int rbytes;
  int pid, status;
  ufd_nr=creat("MeineDatei", 0664);
 
  pid=fork();
 
  if (pid==0) {
    wbytes=write(ufd_nr,buffer,strlen(buffer));
    if (wbytes==-1) printf("Schreibfehler\n");
  } else {
    //wait(&status);
    ufd_nr=open("MeineDatei",0);
    if (ufd_nr==-1) printf("Openfehler\n");
    rbytes=read(ufd_nr,buffer,strlen(buffer));
    if (rbytes==-1) printf("Lesefehler\n");
    buffer[strlen(buffer)]=0;
    printf("Inhalt: \n\n%s",buffer);
  }
  close(ufd_nr);
}

Betriebssystemaufrufe

Bevor jemand fragt, mir gings nicht gut, als ich die Aufgabenstellung ausgefüllt habe ;-)

sigaction2.c

#include <signal.h>
#include <stdio.h>
 
int i = 1;
 
int handler()
{
  if(i < 4)
  {
    printf("%i. CTRL/C gedrückt\n", i);
    i++;
  }
  else
  {
    printf("Programmende\n");
    exit(0);
  }
}
 
main()
{
  static struct sigaction sigact;
		sigact.sa_handler = handler;
		sigemptyset(&sigact.sa_mask);
		sigact.sa_flags = 0;
		if(sigaction(SIGINT, &sigact, NULL) < 0)
			exit(0);
  while (1);
 
}

signal1.c

#include <signal.h>
 
void handler();
 
main() {
 int i;
 
 printf("Test: Signale\n\n");
 
 signal(2, handler);
 
 M: printf("x");
  i=0;
   while(i<200000) i++; //Verzögerung
 goto M;
}
 
void handler() {
 printf("So kannst du mich nicht abbrechen!!\n");
 signal(2, handler);
}

signal2.c

#include <signal.h>
 
void handler();
 
main() {
 int i;
 
 printf("Test: Signale\n\n");
 
 signal(2, handler);
 
 M: printf("x");
  i=0;
   while(i<200000) i++; //Verzögerung
 goto M;
}
 
void handler() {
 printf("So kannst du mich nicht abbrechen!!\n");
 //signal(2, handler);
}

signal3.c

#include <signal.h>
 
void handler();
 
main() {
 int i;
 
 printf("Test: Signale\n\n");
 
 signal(9, handler);
 
 M: printf("x");
  i=0;
   while(i<200000) i++; //Verzögerung
 goto M;
}
 
void handler() {
 printf("So kannst du mich nicht abbrechen!!\n");
 //signal(2, handler);
}

signal4.c

#include <signal.h>
 
void got_SIGFPE() {
 printf("SIGFPE\n");
 exit(0);
}
 
main() {
 unsigned char a=255;a=a/0;	//Devide by Zero
 
 signal(SIGFPE, got_SIGFPE);
 
 printf("a=%i\n",a);
 exit(1);
}

signal5.c

#include <signal.h>
 
unsigned char i=1;
 
void got_SIGALRM() {
 //alarm(5);
 printf("SIGALRM\n");
 i=1;
 exit(1);
}
 
main() {
 signal(SIGALRM, got_SIGALRM);
 
 alarm(5);	//5sec timer 
 
 while (1) {
   printf("%i...\n",i++);
   sleep(1);
 }
}

signal6.c

#include <signal.h>
 
void handler();
 
main() {
 int i;
 
 printf("Test: Signale\n\n");
 
 signal(2, handler);
 
 M: printf("Pause\n");
  pause();
  printf("Weiter nach Pause\n");
 goto M;
}
 
void handler() {
 printf("Abbruch durch Signal 2 unmöglich\n");
 signal(2, handler);
}

signal7.c

#include <signal.h>
 
void got_SIGCHLD() {
 printf("Parent: child died :-(\n");
}
 
main() {
 int pid;
 
 signal(SIGCHLD, got_SIGCHLD);
 
 pid=fork();
 
 if (pid==0) {	//child process
  printf("Child: Iam a child process, my death is coming!\n");
  sleep(1);
  exit(1);
 } else {	//parent process
  printf("Parent: waiting...\n");  
  pause();
  exit(1);
 }
 exit(0);
}

signal10-a.c

#include <signal.h>
 
void got_SIGUSR1() {
  printf("... Signal SIGUSR1 empfangen !!\n");
  signal(SIGUSR1,got_SIGUSR1);
}
 
void got_SIGUSR2() {
  printf("... Signal SIGUSR2 empfangen !!\n");
  signal(SIGUSR2,got_SIGUSR2);
}
 
main() {
 signal(SIGUSR1,got_SIGUSR1);
 signal(SIGUSR2,got_SIGUSR2);
 
 while(1) sleep(1);
}

signal10-b.c

#include <signal.h>
 
#include <getopt.h>
 
int main(int argc, char *argv[]) {
 int pid,signr;
 int opt;
 
 while ((opt = getopt(argc, argv, "p:s:")) != -1) {                  
  switch(opt) {
   case 'p':
     pid=(int)atoi(optarg);
     break;
   case 's':
     signr=(int)atoi(optarg);
     break;
 
   }
  }
 
 printf("calling kill(%i,%i);\n",pid,signr);
 if (kill(pid,signr)>0) {
  return(1);
 } else {
  printf("failed\n");
  return(0);
 }
}
 
wiki/study/prakt/bs.txt · Last modified: 2005/06/02 21:22 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki