Professional Documents
Culture Documents
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(PORT);
OUTPUT:
CLIENT SIDE
SERVER SIDE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
//
// Demonstrates blocking using UNIX open, read, write, close
//
int main(void) {
puts("Client");
char* strMessage[] = {"Welcome", "to", "sjce", "named.", "pipe",
"server", "client", "program","this","will","stop","now"};
//Tidy
close(fd);
return EXIT_SUCCESS;
}
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
int main(void) {
puts("Server - listening");
//Create fifo
unlink("/tmp/demo6_fifo");
int code = mkfifo("/tmp/demo6_fifo", 0666);
if (code == -1) {
perror("mkfifo returned an error - file may already exist");
}
/*
while (strcmp(stringBuffer, "STOP") != 0) {
char L;
read(fd, &L, 1); //Get
string length
read(fd, stringBuffer, L); //Read
string characters
stringBuffer[L] = 0; //Zero
terminator
printf("Server received: %s\n", stringBuffer);
}
*/
int res;
char Len;
while(1) {
res = read(fd, &Len, 1);
if (res == 0) {
break;
}
read(fd, stringBuffer, Len); //Read
string characters
stringBuffer[(int)Len] = 0;
//Zero terminator
printf(" %s", stringBuffer);
}
puts("EOF found");
//Tidy up
close(fd);
puts("FIFO Closed");
return EXIT_SUCCESS;
}
OUTPUT:
CLIENT OUTPUT
SERVER OUTPUT
int main()
{
key_t key;
int msgid;
return 0;
}
3. B) MESSAGE QUEUE SERVER PROGRAM
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdlib.h>
#include <arpa/inet.h>
int main()
{
key_t key;
int msgid;
return 0;
}
OUTPUT
CLIENT OUTPUT
SERVER OUTPUT
struct shmseg {
int cnt;
int complete;
char buf[BUF_SIZE];
};
struct shmseg {
int cnt;
int complete;
char buf[BUF_SIZE];
};
int fill_buffer(char * bufptr, int size);
if (shmdt(shmp) == -1) {
perror("shmdt");
return 1;
}
OUTPUT:
CLIENT OUTPUT
SERVER OUTPUT
5. A) FORK PROGRAM
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
printf("Hello world!\n");
return 0;
}
5. B) WAIT PROGRAM
int main()
{
if (fork()== 0)
wait(NULL);
printf("CT: child has terminated\n");
}
printf("Bye\n");
return 0;
}
OUTPUT:
FORK OUTPUT
WAIT OUTPUT
6. PIPE OPEN AND CLOSE
#include <stdio.h>
#include<stdlib.h>
int main(void)
{
FILE *pipein_fp, *pipeout_fp;
char readbuf[80];
/* Processing loop */
while(fgets(readbuf, 80, pipein_fp))
fputs(readbuf, pipeout_fp);
return(0);
}
OUTPUT:
7. READ PROGRAM
// C program to illustrate
// read system Call
#include<stdio.h>
#include <fcntl.h>
int main()
{
int fd, sz;
char *c = (char *) calloc(100, sizeof(char));
fd = open("foo1.txt", O_RDONLY);
if (fd < 0) { perror("r1"); exit(1); }
sz = read(fd, c, 10);
printf("called read(% d, c, 10). returned that"
" %d bytes were read.\n", fd, sz);
c[sz] = '\0';
printf("Those bytes are as follows: % s\n", c);
}
OUTPUT:
8. WRITE PROGRAM
// C program to illustrate
// write system Call
#include<stdio.h>
#include <fcntl.h>
main()
{
int sz;
close(fd);
}
OUTPUT: