Skip to content
pyoskelPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

26 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project has been created as part of the 42 curriculum by pabartoc (42 Heilbronn).

Minitalk

Description

Minitalk is a small data exchange program using UNIX signals. The goal of this project is to implement a client-server architecture where two independent processes communicate exclusively via Inter-Process Communication (IPC). No network sockets, files, or pipes are allowed—only the signals SIGUSR1 and SIGUSR2.

Because a signal only transmits the binary information of its own arrival, every single character (8 bits) must be broken down into 0s and 1s on the client side, sent individually, and perfectly reassembled on the server side.

Project Structure

The project is strictly organized to keep the source code clean and modular:

.
├── Makefile            # Compiles the project, handles the library, and prevents relinking
├── inc/
│   └── minitalk.h      # Central header file containing all includes, macros, and prototypes
├── src/
│   ├── client.c        # Parses arguments, breaks characters into bits, and sends signals
│   └── server.c        # Listens for signals, reassembles bits, and prints the string
└── ft_printf/          # Custom printf library used for terminal outputs
    ├── Makefile
    ├── ft_printf.c
    ├── ft_printf.h
    └── ft_printf_add_ons.c

Instructions (Execution Visualization)

To run the project, follow this step-by-step process using two terminal windows.

1. Compilation Run make in the root directory to compile both executables (server and client).

$ make

2. Start the Server (Terminal 1) Launch the server. It will immediately print its Process ID (PID) and wait for signals.

$ ./server
Server PID = 12345

3. Send a Message (Terminal 2) Execute the client by providing the server's PID and the string you want to send.

$ ./client 12345 "Hello 42"

(The server in Terminal 1 will now print "Hello 42")

Bit Transmission Visualization

Characters are converted into binary and sent bit by bit (from most significant bit to least significant bit). Here is how the letter 'A' (ASCII value 65) is transmitted:

'A' in binary is 01000001.

Step Bit Position Bit Value Signal Sent
1 Bit 7 (Leftmost) 0 SIGUSR2
2 Bit 6 1 SIGUSR1
3 Bit 5 0 SIGUSR2
4 Bit 4 0 SIGUSR2
5 Bit 3 0 SIGUSR2
6 Bit 2 0 SIGUSR2
7 Bit 1 0 SIGUSR2
8 Bit 0 (Rightmost) 1 SIGUSR1

Learned Concepts & Functions

This project introduced low-level system functions and UNIX signal handling:

  • pid_t: A specialized data type used to securely store Process IDs across different operating systems.
  • getpid: A system call that returns the Process ID (PID) of the currently calling process.
  • kill: Sends a specified signal to a specific PID. Despite the name, it is used here to safely transmit SIGUSR1 or SIGUSR2, not to terminate the process.
  • pause: Suspends the execution of the calling process until a signal is caught, preventing the CPU from running an endless loop at 100% usage.
  • usleep: Suspends the execution of the program for a specified number of microseconds. This is crucial in the client to prevent overwhelming the server's signal queue.
  • signal: The historical, basic function used to set up signal handlers (though we use the more advanced sigaction instead).
  • sigaction: A robust structure and function used to examine or change the action associated with a specific signal. It provides high control over signal blocking.
  • sa_handler: A specific member within the sigaction struct. It is a function pointer that holds the memory address of our custom handler function.
  • sigemptyset: Initializes and empties a signal set (the signal mask), ensuring we start with a clean configuration without accidentally blocking unintended signals.
  • sig_a.sa_flags: A member of our custom sig_a struct used to modify the behavior of the signal handling process. We set it to 0 to use the standard behavior.
  • SIGUSR1 & SIGUSR2: Two user-defined UNIX signals reserved specifically for custom application logic rather than system-level commands.

Resources

  • [Linux Programmer's Manual (man pages) for sigaction, kill, and signals]
  • [AI Usage]: AI was used during this project as a collaborative tutor to explain the theoretical concepts of sigaction vs signal, to visualize the bit-shifting logic, and to help structure this README.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages