Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdlib.h>
#define MAX 10
struct buf_elem {
long mtype;
int mvalue;
};
#define PUSTY 1
#define PELNY 2
main(){
int msgid, i;
struct buf_elem elem;
msgid = msgget(45281, IPC_CREAT|IPC_EXCL|0600);
if (msgid == -1){
msgid = msgget(45281, IPC_CREAT|0600);
if (msgid == -1){
perror("Utworzenie kolejki ókomunikatw");
exit(1);
}
}
else{
elem.mtype = PUSTY;
for (i=0; i<MAX; i++)
if (msgsnd(msgid, &elem, sizeof(elem.mvalue), 0) == -1){
perror("Wyslanie pustego komunikatu");
exit(1);
}
}
for (i=0; i<10000; i++){
if (msgrcv(msgid,&elem,sizeof(elem.mvalue),PUSTY, 0)== -1){
perror("Odebranie pustego komunikatu");
exit(1);
}
elem.mvalue = i;
elem.mtype = PELNY;
if (msgsnd(msgid, &elem, sizeof(elem.mvalue), 0) == -1){
perror("Wyslanie elementu");
exit(1);
}
}
}
==========================1zad
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#define MAX 10
struct buf_elem {
long mtype;
int mvalue;
};
#define PUSTY 1
#define PELNY 2
main(){
int msgid, i;
struct buf_elem elem;
msgid = msgget(45281, IPC_CREAT|IPC_EXCL|0600);
if (msgid == -1){
msgid = msgget(45281, IPC_CREAT|0600);
if (msgid == -1){
perror("Utworzenie kolejki komunikatów");
exit(1);
}
}
else{
elem.mtype = PUSTY;
for (i=0; i<MAX; i++)
if (msgsnd(msgid, &elem, sizeof(elem.mvalue), 0) == -1){
perror("Wyslanie pustego komunikatu");
exit(1);
}
}
for (i=0; i<10000; i++){
if (msgrcv(msgid,&elem,sizeof(elem.mvalue),PELNY,0) == -1){
perror("Odebranie elementu");
exit(1);
}
printf("Numer: %5d Wartosc: %5dn", elem.mvalue);
elem.mtype = PUSTY;
if (msgsnd(msgid, &elem, sizeof(elem.mvalue), 0) == -1){
perror("Wyslanie pustego komunikatu");
exit(1);
}
}
}
==================1zaad
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/shm.h>
#include <stdlib.h>
#define MAX 10
main(){
int shmid, i;
int *buf;
shmid = shmget(45281, MAX*sizeof(int), IPC_CREAT|0600);
if (shmid == -1){
perror("Utworzenie segmentu pamieci wspoldzielonej");
exit(1);
}
buf = (int*)shmat(shmid, NULL, 0);
if (buf == NULL){
perror("Przylaczenie segmentu pamieci wspoldzielonej");
exit(1);
}
for (i=0; i<10000; i++)
buf[i%MAX] = i;
}
=====================zad3
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#define MAX 10
#include <stdlib.h>
main(){
int shmid, i;
int *buf;
shmid = shmget(45281, MAX*sizeof(int), IPC_CREAT|0600);
if (shmid == -1){
perror("Utworzenie segmentu pamieci wspoldzielonej");
exit(1);
}
buf = (int*)shmat(shmid, NULL, 0);
if (buf == NULL){
perror("Przylaczenie segmentu pamieci wspoldzielonej");
exit(1);
}
for (i=0; i<10000; i++)
printf("Numer: %5d Wartosc: %5dn", i, buf[i%MAX]);
}
===================zaad3
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <stdlib.h>
int main(){
int welcomeSocket, newSocket, portNum, clientLen, nBytes;
char buffer[1024];
struct sockaddr_in serverAddr;
struct sockaddr_storage serverStorage;
socklen_t addr_size;
int i;
welcomeSocket = socket(PF_INET, SOCK_STREAM, 0);
portNum = 7891;
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(portNum);
serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
memset(serverAddr.sin_zero, ' ', sizeof serverAddr.sin_zero);
bind(welcomeSocket, (struct sockaddr *) &serverAddr, sizeof(serverAddr));
if(listen(welcomeSocket,5)==0)
printf("Listeningn");
else
printf("Errorn");
addr_size = sizeof serverStorage;
/*loop to keep accepting new connections*/
while(1){
newSocket = accept(welcomeSocket, (struct sockaddr *) &serverStorage, &addr_size);
/*fork a child process to handle the new connection*/
if(!fork()){
nBytes = 1;
/*loop while connection is live*/
while(nBytes!=0){
nBytes = recv(newSocket,buffer,1024,0);
for (i=0;i<nBytes-1;i++){
buffer[i] = toupper(buffer[i]);
}
send(newSocket,buffer,nBytes,0);
}
close(newSocket);
exit(0);
}
/*if parent, close the socket and go back to listening new requests*/
else{
close(newSocket);
}
}
return 0;
}
=================server
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
int main(){
int clientSocket, portNum, nBytes;
char buffer[1024];
struct sockaddr_in serverAddr;
socklen_t addr_size;
clientSocket = socket(PF_INET, SOCK_STREAM, 0);
portNum = 7891;
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(portNum);
serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
memset(serverAddr.sin_zero, ' ', sizeof serverAddr.sin_zero);
addr_size = sizeof serverAddr;
connect(clientSocket, (struct sockaddr *) &serverAddr, addr_size);
while(1){
printf("Type a sentence to send to server:n");
fgets(buffer,1024,stdin);
printf("You typed: %s",buffer);
nBytes = strlen(buffer) + 1;
send(clientSocket,buffer,nBytes,0);
recv(clientSocket, buffer, 1024, 0);
printf("Received from server: %snn",buffer);
}
return 0;
}
============client
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team