stuff
This commit is contained in:
1
Examples/ipc/MYFILE
Normal file
1
Examples/ipc/MYFILE
Normal file
@@ -0,0 +1 @@
|
|||||||
|
HELLO
|
||||||
BIN
Examples/ipc/a.out
Executable file
BIN
Examples/ipc/a.out
Executable file
Binary file not shown.
@@ -43,7 +43,7 @@ int main()
|
|||||||
wait(0);
|
wait(0);
|
||||||
|
|
||||||
/* Read data */
|
/* Read data */
|
||||||
char data[32];
|
char data[32] = {0};
|
||||||
read(myfile, data, sizeof(data));
|
read(myfile, data, sizeof(data));
|
||||||
printf("Parent received %s from child\n", data);
|
printf("Parent received %s from child\n", data);
|
||||||
|
|
||||||
|
|||||||
@@ -4,16 +4,17 @@
|
|||||||
* NOTE: message queues are persistent
|
* NOTE: message queues are persistent
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <mqueue.h> // needed for mq system calls
|
||||||
|
#include <stdio.h> // needed for printf, perror
|
||||||
|
#include <stdlib.h> // needed for exit
|
||||||
|
#include <string.h> // needed for strcpy
|
||||||
#include <sys/types.h> // needed for pid_t
|
#include <sys/types.h> // needed for pid_t
|
||||||
#include <sys/wait.h> // needed for wait system call
|
#include <sys/wait.h> // needed for wait system call
|
||||||
#include <unistd.h> // needed for fork system call
|
#include <unistd.h> // needed for fork system call
|
||||||
#include <stdlib.h> // needed for exit
|
|
||||||
#include <stdio.h> // needed for printf, perror
|
|
||||||
#include <mqueue.h> // needed for mq system calls
|
|
||||||
#include <string.h> // needed for strcpy
|
|
||||||
|
|
||||||
/* Struct for the queue message */
|
/* Struct for the queue message */
|
||||||
typedef struct message {
|
typedef struct message
|
||||||
|
{
|
||||||
int message_id;
|
int message_id;
|
||||||
char string[10];
|
char string[10];
|
||||||
} message;
|
} message;
|
||||||
@@ -29,7 +30,8 @@ int main()
|
|||||||
|
|
||||||
// Create and open a queue
|
// Create and open a queue
|
||||||
mqd_t mqdes = mq_open("/CS3841QUEUE", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR, &queue_attr);
|
mqd_t mqdes = mq_open("/CS3841QUEUE", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR, &queue_attr);
|
||||||
if(mqdes == -1) {
|
if (mqdes == -1)
|
||||||
|
{
|
||||||
printf("COULD NOT OPEN QUEUE\n");
|
printf("COULD NOT OPEN QUEUE\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,18 @@
|
|||||||
* a child process to a parent process
|
* a child process to a parent process
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h> // needed for printf, perror
|
||||||
|
#include <stdlib.h> // needed for exit
|
||||||
#include <sys/types.h> // needed for pid_t
|
#include <sys/types.h> // needed for pid_t
|
||||||
#include <sys/wait.h> // needed for wait system call
|
#include <sys/wait.h> // needed for wait system call
|
||||||
#include <unistd.h> // needed for fork, read, write, close system calls
|
#include <unistd.h> // needed for fork, read, write, close system calls
|
||||||
#include <stdlib.h> // needed for exit
|
|
||||||
#include <stdio.h> // needed for printf, perror
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
/* Create a pipe */
|
/* Create a pipe */
|
||||||
int pipefd[2];
|
int pipefd[2];
|
||||||
if (pipe(pipefd) == -1) {
|
if (pipe(pipefd) == -1)
|
||||||
|
{
|
||||||
perror("pipe");
|
perror("pipe");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@@ -46,7 +47,7 @@ int main()
|
|||||||
close(pipefd[0]);
|
close(pipefd[0]);
|
||||||
|
|
||||||
/* Write to child */
|
/* Write to child */
|
||||||
write(pipefd[1], "HELLO", 5);
|
write(pipefd[1], "HELLO WORLD!", 12);
|
||||||
|
|
||||||
/* Close pipe */
|
/* Close pipe */
|
||||||
close(pipefd[1]);
|
close(pipefd[1]);
|
||||||
|
|||||||
@@ -3,22 +3,24 @@
|
|||||||
* two pipes to send data in two directions
|
* two pipes to send data in two directions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h> // needed for printf, perror
|
||||||
|
#include <stdlib.h> // needed for exit
|
||||||
#include <sys/types.h> // needed for pid_t
|
#include <sys/types.h> // needed for pid_t
|
||||||
#include <sys/wait.h> // needed for wait system call
|
#include <sys/wait.h> // needed for wait system call
|
||||||
#include <unistd.h> // needed for fork, read, write, close system calls
|
#include <unistd.h> // needed for fork, read, write, close system calls
|
||||||
#include <stdlib.h> // needed for exit
|
|
||||||
#include <stdio.h> // needed for printf, perror
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
/* Create pipes */
|
/* Create pipes */
|
||||||
int pipe_to_child[2];
|
int pipe_to_child[2];
|
||||||
if (pipe(pipe_to_child) == -1) {
|
if (pipe(pipe_to_child) == -1)
|
||||||
|
{
|
||||||
printf("PIPE FAILURE\n");
|
printf("PIPE FAILURE\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
int pipe_from_child[2];
|
int pipe_from_child[2];
|
||||||
if (pipe(pipe_from_child) == -1) {
|
if (pipe(pipe_from_child) == -1)
|
||||||
|
{
|
||||||
printf("PIPE FAILURE\n");
|
printf("PIPE FAILURE\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,15 @@
|
|||||||
* NOTE: named shared memory segments are persistent
|
* NOTE: named shared memory segments are persistent
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h> // needed for pid_t
|
|
||||||
#include <sys/wait.h> // needed for wait system call
|
|
||||||
#include <fcntl.h> // needed for parameter values for shm_open
|
#include <fcntl.h> // needed for parameter values for shm_open
|
||||||
#include <unistd.h> // needed for fork, getpid, getppid, kill system calls
|
|
||||||
#include <stdlib.h> // needed for exit
|
|
||||||
#include <signal.h> // needed for signal system call
|
#include <signal.h> // needed for signal system call
|
||||||
#include <stdio.h> // needed for printf, perror
|
#include <stdio.h> // needed for printf, perror
|
||||||
#include <sys/mman.h> // needed for mmap, munmap, shm system calls
|
#include <stdlib.h> // needed for exit
|
||||||
#include <string.h> // needed for strcpy
|
#include <string.h> // needed for strcpy
|
||||||
|
#include <sys/mman.h> // needed for mmap, munmap, shm system calls
|
||||||
|
#include <sys/types.h> // needed for pid_t
|
||||||
|
#include <sys/wait.h> // needed for wait system call
|
||||||
|
#include <unistd.h> // needed for fork, getpid, getppid, kill system calls
|
||||||
|
|
||||||
#define MAPPED_SIZE 128
|
#define MAPPED_SIZE 128
|
||||||
|
|
||||||
@@ -20,7 +20,8 @@ int main()
|
|||||||
{
|
{
|
||||||
// Create and open a shared memory segment
|
// Create and open a shared memory segment
|
||||||
int shmfd = shm_open("/CS3841MEMORY", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
int shmfd = shm_open("/CS3841MEMORY", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
||||||
if(shmfd == -1) {
|
if (shmfd == -1)
|
||||||
|
{
|
||||||
printf("COULD NOT OPEN SHARED MEMORY SEGMENT\n");
|
printf("COULD NOT OPEN SHARED MEMORY SEGMENT\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@@ -31,7 +32,8 @@ int main()
|
|||||||
// Map the segment into the processes address space
|
// Map the segment into the processes address space
|
||||||
// NOTE: protection is set to allow reading and writing with a shared mapping
|
// NOTE: protection is set to allow reading and writing with a shared mapping
|
||||||
void *mapped_space = mmap(NULL, MAPPED_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, 0);
|
void *mapped_space = mmap(NULL, MAPPED_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, 0);
|
||||||
if(mapped_space == MAP_FAILED) {
|
if (mapped_space == MAP_FAILED)
|
||||||
|
{
|
||||||
printf("COULD NOT MMAP\n");
|
printf("COULD NOT MMAP\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,15 @@
|
|||||||
* NOTE: named shared memory segments are persistent
|
* NOTE: named shared memory segments are persistent
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h> // needed for pid_t
|
|
||||||
#include <sys/wait.h> // needed for wait system call
|
|
||||||
#include <fcntl.h> // needed for parameter values for shm_open
|
#include <fcntl.h> // needed for parameter values for shm_open
|
||||||
#include <unistd.h> // needed for fork, getpid, getppid, kill system calls
|
|
||||||
#include <stdlib.h> // needed for exit
|
|
||||||
#include <signal.h> // needed for signal system call
|
#include <signal.h> // needed for signal system call
|
||||||
#include <stdio.h> // needed for printf, perror
|
#include <stdio.h> // needed for printf, perror
|
||||||
#include <sys/mman.h> // needed for mmap, munmap, shm system calls
|
#include <stdlib.h> // needed for exit
|
||||||
#include <string.h> // needed for strcpy
|
#include <string.h> // needed for strcpy
|
||||||
|
#include <sys/mman.h> // needed for mmap, munmap, shm system calls
|
||||||
|
#include <sys/types.h> // needed for pid_t
|
||||||
|
#include <sys/wait.h> // needed for wait system call
|
||||||
|
#include <unistd.h> // needed for fork, getpid, getppid, kill system calls
|
||||||
|
|
||||||
#define MAPPED_SIZE 128
|
#define MAPPED_SIZE 128
|
||||||
|
|
||||||
@@ -21,7 +21,8 @@ int main()
|
|||||||
{
|
{
|
||||||
// Create and open a shared memory segment
|
// Create and open a shared memory segment
|
||||||
int shmfd = shm_open("/CS3841MEMORY", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
int shmfd = shm_open("/CS3841MEMORY", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
||||||
if(shmfd == -1) {
|
if (shmfd == -1)
|
||||||
|
{
|
||||||
printf("COULD NOT OPEN SHARED MEMORY SEGMENT\n");
|
printf("COULD NOT OPEN SHARED MEMORY SEGMENT\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@@ -32,7 +33,8 @@ int main()
|
|||||||
// Map the segment into the processes address space
|
// Map the segment into the processes address space
|
||||||
// NOTE: protection is set to allow reading and writing with a shared mapping
|
// NOTE: protection is set to allow reading and writing with a shared mapping
|
||||||
void *mapped_space = mmap(NULL, MAPPED_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, 0);
|
void *mapped_space = mmap(NULL, MAPPED_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, 0);
|
||||||
if(mapped_space == MAP_FAILED) {
|
if (mapped_space == MAP_FAILED)
|
||||||
|
{
|
||||||
printf("COULD NOT MMAP\n");
|
printf("COULD NOT MMAP\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@@ -76,4 +78,3 @@ int main()
|
|||||||
}
|
}
|
||||||
return 0; // Return success
|
return 0; // Return success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
* for the interrupt (CTRL+C) signal
|
* for the interrupt (CTRL+C) signal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h> // needed for pid_t
|
|
||||||
#include <unistd.h> // needed for getpid, sleep system calls
|
|
||||||
#include <signal.h> // needed for signal system call
|
#include <signal.h> // needed for signal system call
|
||||||
#include <stdio.h> // needed for printf
|
#include <stdio.h> // needed for printf
|
||||||
|
#include <sys/types.h> // needed for pid_t
|
||||||
|
#include <unistd.h> // needed for getpid, sleep system calls
|
||||||
|
|
||||||
// Signal handler
|
// Signal handler
|
||||||
// Prints the PID of the process and the received signal
|
// Prints the PID of the process and the received signal
|
||||||
@@ -22,7 +22,8 @@ int main()
|
|||||||
signal(SIGINT, signal_handler);
|
signal(SIGINT, signal_handler);
|
||||||
|
|
||||||
// Loop forever and sleep
|
// Loop forever and sleep
|
||||||
while(1) {
|
while (1)
|
||||||
|
{
|
||||||
printf("sleeping...\n");
|
printf("sleeping...\n");
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
* fault and essentially loops forever
|
* fault and essentially loops forever
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h> // needed for pid_t
|
|
||||||
#include <unistd.h> // needed for getpid, sleep system calls
|
|
||||||
#include <signal.h> // needed for signal system call
|
#include <signal.h> // needed for signal system call
|
||||||
#include <stdio.h> // needed for printf
|
#include <stdio.h> // needed for printf
|
||||||
|
#include <sys/types.h> // needed for pid_t
|
||||||
|
#include <unistd.h> // needed for getpid, sleep system calls
|
||||||
|
|
||||||
// Signal handler
|
// Signal handler
|
||||||
// Prints the PID of the process and the received signal
|
// Prints the PID of the process and the received signal
|
||||||
|
|||||||
Reference in New Issue
Block a user