About • How to use • Mandatory • Bonus • Norminette • License
This is a server/client system that uses UNIX signals for communication. The server displays its PID and receives decrypted signals as characters, while the client encrypts messages and sends true/false signals using SIGUSR1 or SIGUSR2 to the server's PID.
getpid(void) --> is a system call in Unix-like operating systems that retrieves the process ID (PID) of the calling process and it doesn't accept any arrgument.
#include <unistd.h>
#include <stdio.h>
int main() {
printf("My PID is: %d\n", getpid());
return 0;
}getppid(void) --> is a system call in Unix-like operating systems that retrieves the parent process ID (PPID) of the calling process and it also doesnot accept any argument at getpid.
#include <unistd.h>
#include <stdio.h>
int main() {
printf("My parent's PID is: %d\n", getppid());
return 0;
}#include <signal.h>
#include <stdio.h>
#include <unistd.h>
int main() {
int pid = getpid();
kill(pid, SIGTERM); // Terminates the current process
return 0;
}sleep("number of seconds") --> is a function that causes the current thread to sleep for a specified number of seconds.
#include <stdio.h>
#include <unistd.h>
int main() {
printf("Sleeping for 5 seconds...\n");
sleep(5); // Sleeps for 5 seconds
printf("Woke up after sleeping.\n");
return 0;
}After a successful fork(), two identical processes are created: the parent process and the child process.
#include <stdio.h>
#include <unistd.h>
int main() {
pid_t pid = fork();
if (pid == 0) {
printf("Child process\n");
} else if (pid > 0) {
printf("Parent process\n");
} else {
fprintf(stderr, "Error in forking\n");
}
return 0;
}#include <stdlib.h>
int main() {
// Some program logic...
if (/* Some condition for error */) {
// Error occurred, terminate program with non-zero status
exit(1);
}
// Otherwise, exit program normally with zero status
exit(0);
}#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
void sigint_handler(int signum) {
printf("Received SIGINT signal\n");
// Perform any necessary actions in response to the signal
}
int main() {
// Registering SIGINT handler
signal(SIGINT, sigint_handler);
// Your program logic goes here
// ...
return 0;
}#include <stdio.h>
#include <signal.h>
int main() {
sigset_t set;
// Initialize an empty signal set
sigemptyset(&set);
// Now 'set' represents an empty signal set
// You can add signals to it using sigaddset() if needed
return 0;
}
It takes two arguments: a pointer to a sigset_t data structure representing the signal set, and the signal number you want to add to the set
#include <stdio.h>
#include <signal.h>
int main() {
sigset_t set;
// Initialize an empty signal set
sigemptyset(&set);
// Add SIGINT and SIGTERM to the signal set
sigaddset(&set, SIGINT);
sigaddset(&set, SIGTERM);
// Now 'set' contains SIGINT and SIGTERM signals
// You can use sigismember() to check if a signal is in the set
return 0;
}#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
// Signal handler function for SIGINT
void sigint_handler(int signum) {
printf("Received SIGINT signal\n");
// Perform any necessary cleanup actions
// Terminate the program
exit(EXIT_SUCCESS);
}
int main() {
// Set up signal handler for SIGINT using sigaction
struct sigaction sa;
sa.sa_handler = sigint_handler; // Specify the handler function
sigemptyset(&sa.sa_mask); // Clear the signal mask during handling
sa.sa_flags = 0; // No special flags
// Register the handler for SIGINT
if (sigaction(SIGINT, &sa, NULL) == -1) {
perror("sigaction");
exit(EXIT_FAILURE);
}
// Main program loop
while (1) {
// Your program logic goes here
// In this example, we just sleep indefinitely
sleep(1);
}
return 0;
}git clone https://github.com/mazen-tech/minitalk.gitcd minitalk/minitalk
make./server
./server_bonus./client [SERVER PID] [MESSAGE]
./client_bonus [SERVER PID] [MESSAGE] [EMOTE]make - Compile minitalk mandatory files.
make bonus - Compile minitalk bonus files.
make all - Compile mandatory + bonus files.
make clean - Delete all .o (object files) files.
make fclean - Delete all .o (object files) and .a (executable) files.
make re - Use rules fclean + all.
- Produce server and client executables.
- The Client must communicate a string passed as a parameter to the server (referenced by its process ID) and display it.
- Use
SIGUSR1andSIGUSR2signals only.
- Add reception acknowledgement system.
- Support Unicode characters.
.jpeg)