The purpose of this project is to code a small data exchange program using
UNIX signals.
by: mvaldeta
About signals | Intro
Linux commands are actually individual commands that are able to combine and transmit data to each other through inter-process communication mechanisms.
Linux provides several mechanisms for communication between processes called IPC (Inter-Process Communication):
Signals handling – Communicate by signal
Pipe – Exchange by the pipe mechanism
Message Queues – Exchange through message queues
Shared Memory – Exchange by shared memory segment
Communication via socket
Synchronous communication using semaphore
Images
1
2
3
Signal handling
Signals is one of the oldest methods of interprocess communication used by Unix / Linux systems.
They are used to signal asynchronous events for one or more processes.
Each signal can have a combination or have a signal handler available.
The signal interrupts the processing of the process, forcing the system to
switch to calling the signal processor immediately. At the end of signal processing,
execution resumes.
Each signal is defined with an integer in /urs/include/signal.h.
A list of system constants can be viewed using the kill –l command. For example :
SIGHUP
SIGINT
SIGQUIT
SIGILL
SIGTRAP
SIGABRT
SIGBUS
SIGFPE
SIGKILL
SIGUSR1
SIGSEGV
SIGUSR2
In addition, when executing the man 7 signal command,
we can see the function as well as the instruction manual of each signal type.
Ways to send Signals
From the keyboard
Ctrl + C : sends INT signal (SIGINT) to the process, interrupt the process immediately.
Ctrl + Z : send TSTP signal (SIGTSTP) to process, suspend.
Ctrl + / : sends signal ABRT (SIGABRT) to process, immediately terminates process (abort).
From the command line
The kill command is often used to stop the execution of a process.
The kill command can send any signal to a process, but by default it sends signal 15,
TERM (which is the end of program). like kill -9
2 Signals means using a unit of two
each char is 1 byte | 8 bits
H
E
L
O
72
68
76
79
01001000
01000101
01001100
01001111
get char bit to send:
r= ((message[k] >> i) &1);
transform char bit back into the right position:
c=00000000if (signum==SIGUSR1)
c+= (1 << (6-i));
Usage
$ make
$ ./server #pid will be displayed
$ ./client <pid><message>#pref in a new window
Final notes.
Sure, a real-life Epstein drive is still a few
breakthroughs away. But the rocket-building game
lets you pilot a fusion-propelled craft right now.