dev/c/ParallelsTest/ParallelsTest/Answers.txt

63 lines
2.3 KiB
Plaintext

1.
(a) SIGINT signal sends to the main process
(b) Example of SIGINT signal handler in the attachment: 1.c
2. Signals, shared memory, semaphors, mutexes, critical sections, events, named(streams) and unnamed pipes, sockets, local variables.
3. some_file will contain data(standard input stream) transfered through the unnamed pipe by simbol '|' to the 'echo' command.
In that specific case some_file will contain no data.
4. Unnamed pipe is a set of processes chained by their standard streams.
Named pipe is a method of inter-process communication which has name in the file system tree.
In shell:
$ mkfifo my_pipe
or
$ mknod my_pipe p
will create a fifo pipe
For example we can use it for compress some data.
First process:
$ gzip -9 -c < my_pipe > out.gz
Second:
$ cat Tsoj.txt > my_pipe
and removing pipe:
$ rm my_pipe
or we can use '|' charecter for unnamed pipes (tubes/conveyors).
In C:
Function pipe(int id[2]) declared in unistd.h will create unnamed pipe,
example of using it: 4unpipe.c is in the attachment.
Function mkfifo (const char *filename, mode_t mode) declared in 'sys/stat.h'
may create named pipe. Example: 4npipe.c is in the attachment.
If the receiving end of a pipe dies while the sending end still wants to write to the pipe
sending end will die too !
5. (a) TCP server: socket, bind, listen, accept;
(b) TCP client: socket, connect.
6. The program prints "Hello world!\n" of maximum child process number in UNIX times.
10240 times on my Linux system. And then the program exits with bad status.
7. In run time we can use 'lsof' or 'fuser' command to find out is it opening any file or not.
'ldd' use to find out which libraries it uses when not running executable file.
finally $hex some.out|less, then press '/', input file name and search for the binary code.
8. Something like this:
telnet mail.server.ua 25
helo 95.83.108.87
mail from: mecareful@server.ua
rcpt to: somebody@somewhere.com
Subject: Test letter
Please don't reply to this letter.
quit
9. Hard link is a directory reference, or pointer, to a file on a storage volume.
$ ln some_file hard_link
creates a hard link hard_link with the same node as a some_file.
Example 9.sh in the attachment shows which three files are hardlinked to each other.
10. I use /proc/self/fd, example in the attachment: 10.c.