Lab 6 : Pipe – Grep – System
Learning goals: in this laboratory activity you will learn how to use exec
family and system system calls in order to execute commands. You will
also improve your understanding about the sort command and you will learn how to combine grep and sort command
in order to perform complex tasks.
Exercise 1
Write a C program that:
1.receives a file name(fname) and a number(n) as command line
parameters
2.executes the commands, listed in “fname” file, sequentially
3.sleeps n seconds before executing the next command.
Write two versions of the program:
1.First one by using the system function;
2.Second one by using exec(choose the suitable exec function from the
exec family!) ;
Find below a commad file(fname) example(each line contains a command +
parameters):
ls -l -a
cat main.c
mkdir src
cp main.c src/
Exercise 2
Download the file data.txt from the website and using sort, grep, redirection
and pipes:
1.Sort data in reverse order by person id number;
2.Sort data by surname;
3.Sort data by surname and if the surname is the same by person id;
/
>
sort-k2,2 -k1,1
data.txt
Note:
To sort by a single column, use -k2,2
as the key specification. This means to use the fields from #2 to #2,
i.e. only the second field.
/
>
key specification like -k2
means to take all
the fields from 2 to the end of the line into account.
4.Filter all the person that have attended the course in 2011-2012;
5.Count the number of person who attended in 2011-2012;
Exercise 3
Write a C program that implements the following precedence graph(use fork
,wait, waitpid system calls):
Summary
At the end of this laboratory activity you should have understood how to
use system and exec system calls . You should have understood the difference between exec and
system system calls, and how to use/combine sort and grep commands. Finally you should also know
how to implement a precedence graph using fork, wait and waitpid system calls.
Can you please provide the solutions to all of these exercises?
ReplyDeletehttps://www.youtube.com/watch?v=kLC-LoKvdIw&list=PL2bE7itI_Ia5MTQa6__AmbXTwOZ_DtP9t&index=10
DeleteThis is the youtube link of the solution: of this lab.
enjoy !! and thanks for the comment