Task 1 ====== ps -fu [username] kill -9 pid Task 2 ====== To start a process: nice -n +5 top (higher nice value means lower priority) For running process: renice +5 pid Task 3 ====== #include main() { int pid; /* child process is created using fork */ pid = fork(); /* fork returns -1 if the child process cannot be created */ if (pid < 0) { /* Show error message */ fprintf(stderr,"Fork failed"); /* exit program with error status */ exit(-1); } /* pid is zero for child */ if (pid == 0) { /* Execute top program in child process*/ execlp("/usr/local/bin/top","top",NULL); } /* pid is nonzero positive integer for parent */ else { /* wait until child has executed */ wait(NULL); /* Show message */ printf("Child complete\n"); /* Exit program with a succesfull status 0*/ exit(0); } } Task 4 ====== #include main() { /* Create 1st child and execute top in it */ /* NOTE: if execlp is succesfully executed, then child is terminated */ if (fork() == 0) {execlp("/bin/who","who",NULL);} /* Create 2nd child and execute top in it */ if (fork() == 0) {execlp("/bin/finger","finger",NULL);} /* This is in parent process */ /* Wait all processes (wait will return -1, if there are not childs)*/ while(wait(NULL) != -1); printf("Childs completed\n"); /* exit program */ exit(0); } Task 5 ====== #include #include main() { int putki[2], pid, N; /* create pipe, if pipe returns -1 it cannot be created */ if (pipe(putki) != 0) {perror("pipe"); exit(1);} /* create a child */ pid = fork(); if (pid == -1) {perror("fork"); exit(1);} if (pid != 0) { /* this is in parent process */ char message1[1024]; /* close pipe writing fd, it is not needed */ close(putki[1]); /* read from pipe */ if (read(putki[0],message1,1024) < 0) {perror("read putki"); exit(1);} /* Show message read from pipe */ printf("Child: %s\n",message1); /* close pipe reading fd */ close(putki[0]); printf("Parent: Yes.\n"); }else{ char message2[1024]; /* close pipe reading fd, it is not needed */ close(putki[0]); /* copy a string */ strcpy(message2,"Can you hear me ?"); /* alculate the length of a string */ /* NOTE: The strlen() function calculates the length of the string */ /* not including the terminating `\0' character */ N=strlen(message2); /* write message2 to a pipe */ if (write(putki[1],message2,N+1) != N+1) {perror("write putki"); exit(2);} /* close pipe writing fd, it is not needed*/ close(putki[1]); } /* exit a program */ exit(0); }