Implementation of File System Calls
Implementation of File System Calls
Implementation of File System Calls
#include<fcntl.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int n, fd;
char buff[50];
clrscr();
printf("Enter text to write in the file:");
n=read(0, buff, 50);
fd=open("file", O_CREAT | O_RDWR, 0777);
write(fd, buff, n);
write(1, buff, n);
close(fd);
getch();
}
OUTPUT:
import java.io.*;
public class pipe
{
public static void main(String[]args) throws IOException
{
PipedInputStream input=new PipedInputStream();
PipedOutputStream output=new PipedOutputStream();
try
{
input.connect(output);
output.write(71);
System.out.println("using read();"+(char)input.read());
output.write(69);
System.out.println("using read();"+(char)input.read());
output.write(75);
System.out.println("using read();"+(char)input.read());
}
catch(IOException except)
{
except.printStackTrace();
}
}
}
Output:
system03@System03-PC:~/Desktop$ javac pipe.java
system03@System03-PC:~/Desktop$ java pipe
using read();G
using read();E
using read();K
Implementation Of IPC Techniques(Message Queue)
import java.util.LinkedList;
import java.util.Queue;
public class queue{
}
Output:
Server program:
import java.net.*;
import java.io.*;
import java.util.*;
class tcpser
{
public static void main(String arg[])
{
ServerSocket ss = null;
Socket cs;
PrintStream ps;
BufferedReader dis;
String inet;
try
{
ss = new ServerSocket(4444);
System.out.println("Press Ctrl+C to quit");
while(true)
{
cs = ss.accept();
ps = new PrintStream(cs.getOutputStream());
Date d = new Date();
ps.println(d);
dis = new BufferedReader(new
InputStreamReader(cs.getInputStream()));
inet = dis.readLine();
System.out.println("Client System/IP address is :"+ inet);
ps.close();dis.close();
}
}
catch(IOException e)
{
System.out.println("The exception is :" + e);
}
}
}
Client program
import java.net.*;
import java.io.*;
class tcpcli
{
public static void main (String args[])
{
Socket soc;
BufferedReader dis;
String sdate;
PrintStream ps;
try
{
InetAddress ia = InetAddress.getLocalHost();
if (args.length == 0)soc = new Socket(InetAddress.getLocalHost(),4444);
else
soc = new Socket(InetAddress.getByName(args[0]),4444);
dis = new BufferedReader(new
InputStreamReader(soc.getInputStream()));
sdate=dis.readLine();
System.out.println("The date/time on server is : " +sdate);
ps = new PrintStream(soc.getOutputStream());
ps.println(ia);
ps.close();
}
catch(IOException e)
{
System.out.println("THE EXCEPTION is :" + e);
}
}
}
OUTPUT:
server side:
system03@System03-PC:~/Desktop$ javac tcpser.java
system03@System03-PC:~/Desktop$ java tcpser
Press Ctrl+C to quit
Client System/IP address is :System03-PC/127.0.1.1
Client side:
system03@System03-PC:~/Desktop$ javac tcpcli.java
system03@System03-PC:~/Desktop$ java tcpcli
The date/time on server is : Mon Mar 09 13:09:24 IST 2020
Socket Programming( UDP Sockets)
Server Program:
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
ds.receive(DpReceive);
System.out.println("Client:-" + data(receive));
if (data(receive).toString().equals("bye"))
{
System.out.println("Client sent bye.....EXITING");
break;
}
Client program:
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;
InetAddress ip = InetAddress.getLocalHost();
byte buf[] = null;
System.out.println("Type any Text:");
while (true)
{
String inp = sc.nextLine();
buf = inp.getBytes();
DatagramPacket DpSend =
new DatagramPacket(buf, buf.length, ip, 1234);
ds.send(DpSend);
if (inp.equals("bye"))
break;
}
}
}
OUTPUT:
Client:
system03@System03-PC:~/Desktop$ javac udpcli.java
system03@System03-PC:~/Desktop$ java udpcli
Type any Text:
HELLO
I AM CLIENT
HI
bye
Server:
system03@System03-PC:~/Desktop$ javac udpser.java
system03@System03-PC:~/Desktop$ java udpser
Client:-HELLO
Client:-I AM CLIENT
Client:-HI
Client:-bye
Client sent bye.....EXITING
Output:
OUTPUT:
RPC
Server:
import java.io.*;
import java.net.*;
class ser
{
public static void main(String[] args) throws Exception
{
ServerSocket sersock = new ServerSocket(3000);
System.out.println("Server ready");
Socket sock = sersock.accept( );
BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
InputStream istream = sock.getInputStream();
BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
String receiveMessage, sendMessage,fun;
int a,b,c;
while(true)
{
fun = receiveRead.readLine();
if(fun != null)
System.out.println("Operation : "+fun);
a = Integer.parseInt(receiveRead.readLine());
System.out.println("Parameter 1 : "+a);
b = Integer.parseInt(receiveRead.readLine());
if(fun.compareTo("add")==0)
{
c=a+b;
System.out.println("Addition = "+c);
pwrite.println("Addition = "+c);
}
if(fun.compareTo("sub")==0)
{
c=a-b;
System.out.println("Substraction = "+c);
pwrite.println("Substraction = "+c);
}
if(fun.compareTo("mul")==0)
{
c=a*b;
System.out.println("Multiplication = "+c);
pwrite.println("Multiplication = "+c);
}
if(fun.compareTo("div")==0)
{
c=a/b;
System.out.println("Division = "+c);
pwrite.println("Division = "+c);
}
System.out.flush();
}
}
}
Client:
import java.io.*;
import java.net.*;
class cli
{
public static void main(String[] args) throws Exception
{
Socket sock = new Socket("127.0.0.1", 3000);
BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
InputStream istream = sock.getInputStream();
BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
System.out.println("Client ready, type and press Enter key");
String receiveMessage, sendMessage,temp;
while(true)
{
System.out.println("\nEnter operation to perform(add,sub,mul,div)....");
temp = keyRead.readLine();
sendMessage=temp.toLowerCase();
pwrite.println(sendMessage);
System.out.println("Enter first parameter :");
sendMessage = keyRead.readLine();
pwrite.println(sendMessage);
System.out.println("Enter second parameter : ");
sendMessage = keyRead.readLine();
pwrite.println(sendMessage);
System.out.flush();
if((receiveMessage = receiveRead.readLine()) != null)
System.out.println(receiveMessage);
}
}
}
Output:
Server:
system03@System03-PC:~/Desktop$ javac ser.java
system03@System03-PC:~/Desktop$ java ser
Server ready
Operation : add
Parameter 1 : 5
Addition = 13
Client:
system03@System03-PC:~/Desktop$ javac cli.java
system03@System03-PC:~/Desktop$ java cli
Client ready, type and press Enter key
try
{
System.out.println("\n Enter Host Name ");
String hname=in.readLine();
InetAddress address;
address = InetAddress.getByName(hname);
System.out.println("Host Name: " + address.getHostName());
System.out.println("IP: " + address.getHostAddress());
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}
Output:
system03@System03-PC:~/Desktop$ javac dns.java
system03@System03-PC:~/Desktop$ java dns
in.close();
}
}
Output:
system03@System03-PC:~/Desktop$ javac http.java
system03@System03-PC:~/Desktop$ java http
{"login":"google","id":1342004,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzNDIwMDQ=","ava
tar_url":"https://avatars1.githubusercontent.com/u/1342004?
v=4","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/
google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://
api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/go
ogle/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}
{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_
url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/r
epos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url"
:"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false,
"name":"Google","company":null,"blog":"https://opensource.google/","location":null,"email":"o
[email protected]","hireable":null,"bio":"Google ❤️Open
Source","public_repos":1689,"public_gists":0,"followers":0,"following":0,"created_at":"2012-
01-18T01:30:18Z","updated_at":"2019-12-19T21:09:14Z"}