Task 1 ====== man man man -k wait man -s 2 wait apropos = man -k whatis = man -f Task 2 ====== who | sort Extra example using pipes: Show 25 most common given names of users who have user account in cs-computer. Solution: cat /etc/passwd | awk -F: '{print $5}' | awk '{print $1}' | sort | uniq -c | sort -n | tail -25r Task 3 ====== Using dup --------- #include main() int putki[2]; int pid,pid2; /* create a pipe */ if (pipe(putki) != 0) {perror("pipe"); exit(1);} /* Parent creates 1st child */ pid = fork(); if (pid == -1) {perror("fork"); exit(1);} if (pid == 0) { /* This is the 1st child */ /* Close standard out (writing) and redirect putki[1] to it */ close(1); dup(putki[1]); /* close putki[0] and putki[1] of child */ close(putki[0]); close(putki[1]); /* exec who, which writes to standard output */ execlp("who","who",NULL); } else /* Parent process*/ { /* Parent creates 2nd child */ pid2 = fork(); if (pid2 == -1) {perror("fork"); exit(1);} if (pid2 == 0) { /* This in the 2nd child*/ /* Sort reads here from standard input */ /* Close standard in (reading) and redirect putki[0] to it */ close(0); dup(putki[0]); /* close putki[0] and putki[1] of child */ close(putki[0]); close(putki[1]); /* sort gets input from standard in */ execlp("sort","sort",NULL); } printf("Childs completed\n"); exit(0); } } Using dup2 ---------- #include main() int putki[2]; int pid,pid2; /* create a pipe */ if (pipe(putki) != 0) {perror("pipe"); exit(1);} /* Parent creates 1st child */ pid = vfork(); if (pid == -1) {perror("fork"); exit(1);} if (pid == 0) { /* This is the 1st child */ dup2(stdout,putki[1]); /* close putki[0] and putki[1] of child */ close(putki[0]); close(putki[1]); /* exec who, which writes to standard output */ execlp("who","who",NULL); } else /* Parent process*/ { /* Parent creates 2nd child */ pid2 = vfork(); if (pid2 == -1) {perror("fork"); exit(1);} if (pid2 == 0) { /* This in the 2nd child*/ /* Sort reads here from standard input */ /* Close standard in (reading) and redirect putki[0] to it */ dup2(stdin,putki[0]); /* close putki[0] and putki[1] of child */ close(putki[0]); close(putki[1]); /* sort gets input from standard in */ execlp("sort","sort",NULL); } printf("Childs completed\n"); exit(0); } } NOTE: also popen can be used to create a pipe between the calling program and the command to be executed. Task 4 ====== man -k scheduler man sched_setscheduler or man sched more detailed information in /usr/include/sched.h Three scheduling policies are defined; others may be defined by the system. The three standard policies are indicated by the values of the following symbolic constants: SCHED_FIFO First in-first out (FIFO) scheduling policy. SCHED_RR Round robin scheduling policy. SCHED_OTHER Another scheduling policy.