Friday 27 April 2012

How to call C functions in python ,A tutorial of swig

Here we shall use a binary search tree c program and invoke the same from python

The c function file : download here , name it as bst.c
The swig interface file : download here , name it as bst.i
The make file would be : saved as mf


all:bst.o bst_wrap.o
    ld -shared bst.o bst_wrap.o -o _bst.so    
    python p.py   

bst_wrap.c:bst.i   
    swig -python bst.i

bst.o:bst.c
    gcc -c bst.c  -o bst.o  -I/usr/include/python2.6
   

bst_wrap.o:bst_wrap.c
    gcc -c bst_wrap.c -o bst_wrap.o -I/usr/include/python2.6
   
  
kindly note that the path to python directory and the version may be different for you .



The python p.py file :

import bst
bst.bst()





Execute the make file  as > make -f mf


But with the make file:











<A tutorial and explanation for all stuff's mentioned here will be provided asap>

Thursday 26 April 2012

Page Replacement in c ,A simulation

Least recently used: download code here
Optimal page replacement : download code here
First come first out: download code here
A shell script for providing graphs of the page replacement is also provided
in case you dont want to use it ,modify the codes above accordingly

The shell script being



#!/bin/sh

gnuplot -persist <<PLOT

plot 'a' using 1:2 title 'page replacement' with lines;set xlabel 'time'; set ylabel 'fault'

quit
PLOT




Save the above in a text file as plo.sh (or any other name for that you may need to modify the name as well in the c codes above)

<The explanation for the above codes will be provided shortly >

Scheduling using threads

Thread based programming for simulation of :

First come first serve : download code link here
Multi level queue : download code link here
Multi level Queue with feed back : download code link here
Threads with Priority : download code link here
Round Robin:download code here
Shortest Job first:download code here

<A tutorial on thread based programming and a brief summary of the codes will be provided shortly >