Return to Operationg Systems home
Write a C program that reads integer numbers and prints in standard output (stdout
)
fprintf (stdout, ...);
the even numbers and in standard error (stderr
)
fprintf (stderr, ...);
the odd numbers. The program must terminate after the introduction of the value 0
.
Make use of redirection for:
inFile.txt
”, instead of from standard inputevenFile.txt
”, instead of standard outputoddFile.txt
”, instead of standard error.Use pipe and redirection on shell command to perform the following operations:
home
” directory (do not analyze sub-directories)root
” (Suggestion: use the command man ps
to analyze the option -U
of the command).The sorting algorithms by exchange (exchange-sort or bubble-sort) sort a vector comparing adjacent elements. The following is a possible implementation (with sorting of the vector v of n elements):
for (i=0; i<n-1; i++) { for (j=0; j<n-1-i; j++) { if (v[j] > v[j+1]) { val = v[j]; v[j] = v[j+1]; v[j+1] = val; } } }
A binary file can be write (UNIX function write
) or read (UNIX function read
) using a random access by means of the function lseek
.
For example, the program lab04ex02.c, after receiving the name of a file from command line,
vet
with 12 elementsImplement in a concurrent and multi-process way the bubble-sort algorithm.
The algorithm, by using the system calls fork
and wait
, and sharing data in the file (i.e., by reading and writing data in the same file), must order the file itself.
The program (i.e., the parent):
n
of integer numbers.n-1-i
child processesEach of its children:
i
.sizeof(int)
bytes,sizeof(int)
bytes,\n
character of end of line.Write a program that, using signals, synchronize two processes (a parent and it child) in a way that they print alternatively a specific message.
The following is an example of output:
Child Woke-up Father Woke-up Child Woke-up Father Woke-up Child Woke-up Father Woke-up Child Woke-up Father Woke-up ...
Insert appropriate sleep
to avoid race conditions.
Implement a C program that generates two children, a producer and a consumer. The producer child reads from the keyboard some strings, and it transfers them to the consumer. The consumer child converts the strings into uppercase characters, and it visualizes the strings in standard output.
The introduction of the string “end” terminates both children's processes and then, in sequence, it terminates the parent process. The transfer of the strings has to take place through a file.
Suggestions: