Client-Server for arithmetic calculations. The communication is through signals and files in Linux.
- The server deletes the last file used for communication with a client -
to_srv.txt
(if it exists) to enable new connections. - The server wait for a new signal from clients.
- The server creates a child to handle the client from whom it got the signal.
The child then will -- read the data from the file the client made for it.
- delete the
to_srv.txt
file (to enable new connections). - create a file with the result of the client exercise with the name
to_client_xxxx.txt
(xxxx = client pid). - send a signal to the client that the result is ready. The server will return to wait for new clients while the child is running.
The client -
- create the file for communication with the server -
to_srv.txt
.
If the file exists, the client will try ten times to create a new one, and between each try, it will wait for one to five seconds (randomly). After ten tries, if the client has not succeeded, it will close with an appropriate message. - add the relevant arguments from the terminal to the file.
The arguments are -arg[0]
- the program name.arg[1]
- the server pid.arg[2]
- the first number.arg[3]
- the arithmetic operation (1-4) -- 1 is +
- 2 is -
- 3 is *
- 4 is /
arg[4]
- the second number. The client addsarg[2], arg[3], arg[4]
to file, and also its pid.
- send a signal to the server and modify it that the file is ready.
- wait for a signal from the server.
- after getting the signal from the server, the client will read the data from the file had made for the client -
to_client_xxxx.txt
(xxxx = client pid), will write it to the screen and delete the file.
There are a few steps -
- Clone into the project using git bush or terminal with this commend -
git clone https://github.com/Liri-Be/LinuxSignals.git
- Open the terminal in the code directory.
- Run those commands to create executable files from the C files -
You can use any name you want instead of
gcc -o server.out server.c gcc -o client.out client.c
server.out
andclient.out
. - Run the server in the background with this command -
This command will show the process id of the server.
./server.out&
- Run the client -
./client.out p1 p2 p3 p4
- p1 - the server's process id
- p2 - the first number
- p3 - the arithmetic operation (1-4) -
- 1 is +
- 2 is -
- 3 is *
- 4 is /
- p4 - the second number