> For the complete documentation index, see [llms.txt](https://42-guide.gitbook.io/42-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://42-guide.gitbook.io/42-guide/core-curriculum/rank-02/integrations/what-to-do.md).

# What to do ?

### 1. Understanding the Project

#### Objective

* **Create a server program** that listens for incoming messages.
* **Create a client program** that sends messages to the server.
* **Use UNIX signals** (SIGUSR1 and SIGUSR2) for communication.

***

### 2. What are Signals?

**Signals** are software interrupts that notify a process of events. Some commonly used signals include:

* **SIGINT (2)**: Interrupt signal (Ctrl+C).
* **SIGKILL (9)**: Forces a process to terminate.
* **SIGTERM (15)**: Requests a process to terminate.
* **SIGUSR1 (10)** and **SIGUSR2 (12)**: User-defined signals, used in Minitalk.

In Minitalk, **SIGUSR1** and **SIGUSR2** are used to transmit binary data (1s and 0s).

***

### 3. How Does It Work?

Since signals can only send a small amount of information (only which signal was sent), we need to encode characters as binary and send them bit by bit.

#### Basic Process:

1. The client **sends the server the PID** (Process ID).
2. The client **converts the message into binary**.
3. The client **sends each bit of each character** using **SIGUSR1** (0) and **SIGUSR2** (1).
4. The server **receives the bits** and **reconstructs the original message**.

***

### 4. Step-by-Step Implementation

#### 4.1 Server

The server will:

* Print its own PID (so the client knows where to send data).
* Listen for **SIGUSR1** and **SIGUSR2** signals.
* Decode the binary message into characters.
* Print the received message.

**4.1.1 Server Code Explanation**

* Use `getpid()` to print the server PID.
* Use `signal()` or `sigaction()` to listen for **SIGUSR1** and **SIGUSR2**.
* Construct each character bit by bit (8 bits = 1 character).
* Print the final message.

#### 4.2 Client

The client will:

* Get the server's PID as an argument.
* Convert the message into binary.
* Send each bit to the server using **SIGUSR1** (0) and **SIGUSR2** (1).
* Introduce a small delay between signals to ensure processing.

**4.2.1 Client Code Explanation**

* Convert each character into its binary representation.
* Send one bit at a time using `kill(server_pid, SIGUSR1/SIGUSR2)`.
* Wait for a short delay to avoid overwhelming the server.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://42-guide.gitbook.io/42-guide/core-curriculum/rank-02/integrations/what-to-do.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
