Wednesday, 9 September 2015

Assignment No: 04





Q1. Explain IPC

Q2. What is Process Tracing ?

Q3. What is System V IPC?

Q4. Explain Network Communication different technics

Q5.What is Master Slave Processor?

Q6. Explain Tunis System.

Assignment No: 03




Q1. Explain Memory System with Its types

Q2. What is Address Binding ?

Q3. What is Mean by Linking & Loading in memory system?

Q4. Explain Memory management Techniques

Q5. Explain  types of Memory Partitioning

Q6. What is Paging?

Q7. What is Segmentation? Explain Page replacement strategy

Q7. Explain Virtual Memory

Tuesday, 25 August 2015

PR( 05) Write a program in C++ to create a RAMDRIVE and associate an acyclic directory structure to it. Use this RAMDRIVE to store input, out files to run a calculator program.

cal.c

#include<iostream>
#include<fstream>
#include<sys/types.h>
#include<stdlib.h>

using namespace std;

int main()
{
    int a,b,c,ch;
    FILE *fp;

    // The two numbers are stored in input.txt file

    fp = fopen("/mnt/ramdisk1/input.txt","r");        // Open input.txt file stored in RAMDISK
    fscanf(fp, "%d", &a);   
    fscanf(fp, "%d", &b);
    fclose(fp);                        // Close the file

    fp = fopen("/mnt/ramdisk1/output.txt","w");        // Open (Create if not exist) the output.txt file stored in RAMDISK
    fprintf(fp, "\n Addition: %d", (a+b));            // Write addition in file
    fprintf(fp, "\n Subtraction: %d", (a-b));        // Write subtraction in file
    fprintf(fp, "\n Multiplication: %d", (a*b));        // Write multiplication in file
    fprintf(fp, "\n Division: %d", (a/b));            // Write division in file

    return 0;
}
 ****************************************************************************************

 ramdisk.c


#include <stdio.h>
#include <stdlib.h>

long long create_ramdisk(void)
{
FILE *fp;
int ch;
long long space = 0;
system("mkdir -p /mnt/ramdisk");
system("/sbin/mke2fs -q /dev/ram");
system("mount /dev/ram /mnt/ramdisk");
system("df /mnt/ramdisk tmp.txt");
fp = fopen("tmp.txt", "r");
if(!fp)
{
printf("Can't open file\n");
return 0;
}
while((ch = fgetc(fp)) != EOF && ch != '\n');
while((ch = fgetc(fp)) != EOF && ch != ' ');
while((ch = fgetc(fp)) != EOF && ch == ' ');
while((ch = fgetc(fp)) != EOF && ch != ' ');
while((ch = fgetc(fp)) != EOF && ch == ' ');
while((ch = fgetc(fp)) != EOF && ch != ' ');
while((ch = fgetc(fp)) != EOF && ch == ' ');
ungetc(ch, fp);
if(feof(fp))
{
printf("Unexpected read\n");
return 0;
}
fscanf(fp, "%lld", &space);
fclose(fp);
remove("tmp.txt");
return space;
}

void remove_ramdisk(void)
{
system("umount /mnt/ramdisk");
}

int main(void)
{
long long space = create_ramdisk();
printf("Ramdisk has %lld bytes free\n", space);
remove_ramdisk();
return 0;
}


*******************************************************************************************

ramdisk.cpp
#include<iostream>

#include<sys/types.h>
#include<stdlib.h>

using namespace std;

main()
{
    int ch;
    do
    {
        cout<<"\n Switch to the Superuser mode for better results.\n";
        cout<<"\n MENU";
        cout<<"\n 1. Check Free Space";  
        cout<<"\n 2. Create RAMDISK";
        cout<<"\n 3. Copy Files to RAMDISK";
        //cout<<"\n 4. Run Calculator program";
        //cout<<"\n 4. See the contents of Output file";
        cout<<"\n 4. Unmount RAMDISK";
        cout<<"\n 5. Exit";

        cout<<"\n\n Enter Your Choice: ";
        cin>> ch;

        switch(ch)
        {
            case 1:
                system("df -h");
                break;
            case 2:
                system("rmdir /mnt/ramdisk1");  
                system("mkdir /mnt/ramdisk1");
                system("chmod 777 /mnt/ramdisk1");
      
                system("mount -t tmpfs -o size=256m tmpfs /mnt/ramdisk1");
                break;
            case 3:
                // copy input.txt and calculator (object file of calculator.cpp) to RAMDISK
                system("cp input.txt /mnt/ramdisk1");      
                system("cp calculator /mnt/ramdisk1");
                cout<<"Files successfully copied to RAMDISK.";
                break;
            /* case 4:
                system("/mnt/ramdisk1/calculator");
                break; */
            case 4:
                system("umount /mnt/ramdisk1");
                break;
            case 5:
                return 0;                  
        }
        cout<<"Do you want to continue? (1/0): ";
        cin>> ch;
   
    } while(ch == 1);  

    return 0;

}
 

Wednesday, 29 July 2015

PR(03): Socket Programming using python



Client.py

#!/use/bin/python

import socket

s = socket.socket()

host = socket.gethostname()

port = 12352

s.connect((host, port))

print "Enter the file name: "

name = raw_input()

s.send(name)

print "The contents of file ", name , "are: "
print s.recv(65536)
s.close
**************************************************************************************

  Server.py


#!/usr/bin/python

# Server Program: server.py

import socket  # import socket module
import os

s=socket.socket() # Create a socket object
host = socket.gethostname()   # Get local machine name
port = 12352      # serve port for yout service
s.bind((host, port))    # Bind to the port

s.listen(10)      # Wair for client connection

while True:
      c, addr = s.accept()    # Establish connection with client
      print 'Got connection from ', addr
      name = c.recv(100)      # Receive filename from client
      print name, 'File requested by client'
      file = open(name, "r")  # Open file requested by client
     
      while True:
            chunk = file.read(65536)      # Read file contents
            if not chunk:
                  break             # EOF
            c.sendall(chunk)  # Send file contents to client

c.close()

Monday, 27 July 2015

PR(02) Process Communication using Pipe



#!/usr/bin/python

import os, sys

print "The child will write text to a pipe and "
print "the parent will read the text written by child..."

# file descriptors r, w for reading and writing
r, w = os.pipe()

processid = os.fork()
if processid:
    # This is the parent process
    # Closes file descriptor w
    os.close(w)
    r = os.fdopen(r)
    print "Parent Process is reading..."
    str = r.read()
    str=str[::-1]
    print "Text read by Parent Process :", str  
    sys.exit(0)
else:
    # This is the child process
    os.close(r)
    w = os.fdopen(w, 'w')
    print "Child Process is writing"
    w.write("Mahesh")
    w.close()
    print "Child Process is closing"
    sys.exit(0)