Friday, May 31, 2013
Using a Linux RSA key with Putty for Logging in from Windows Machine to Linux SSH Server
Thursday, May 30, 2013
Important Lessons to Learn From OpenSource
Open Source is all about openness, freedom, and community and somewhat all the above. Is it ?
From standpoint of a fresher, and being thrown at opensource is probably the best thing that happened to my life. Being a bengali and inheriting some cultural communism traits from my homeland Bengal, i really felt this overwhelmingly fun. Here by this post i make an attempt to share my views in context to what i have learnt from this industry valuable to my life.
DIY (Do it yourself)
We often come in situations where a responsibility of fixing a thing is not a individuals choice but is critical in a line of things. The important perception in this scenario is that i and you create we and all such we's create the community. If somebody takes even a small step to fix a thing, that gets magnified by the community as a stable next release.
Design Principles
Open Source design principles involve a lot of variables because of distribution of development workforce. The Bazaar Model discusses all such problems. In these challenges, simple analogies of modularity, control makes it possible for the others to contribute. All these actually are pieces of human aspects put to use to deal with any kind of creative work from somebody being as learned and experienced as a Chief Technology Office to a Junior Programmer. Being modular makes life more simple.
Hacktivism
This is a term coined for somebody who is not satisfied the usual and want to know more of the details by opening a black box. Though this term might seem very awesomely violent to some people and a act of copyright infringement for corporate. it is not so. It is derivative of common man inquisition and quest for learning and a little of "Lets Make Things Work" in a way it is not destructive at all. As long as there is hacktivism in the industry, there is whole new application idea coming to surface every now and then. Looking into a system internal gives more control over usual in a good way.
A Different Taste Everyday
Opensource gives more than it takes. With tons of opensource tools available on the horizon, we have a very widespread choice in the horizon. This is one of the real fun trying out new software to mold some of the very essential lifestyle choices. Starting from reading up mail to set up a cloud storage for your essential files, you can customize and program you way for a new and different way of doing stuff.
New ways of doing or new look and feel the same thing is always rejuvenating.
A New detective Story Everyday
Somebody related to software has a certain levels of pessimism in their lives, maybe because of the fact that no software is well enough to be perfect at its run-time To learn new ways the system can go wrong is just a another bug in our lives. Here simple lessons of perseverance, optimism scrutiny, and zest in improving the system drives this creativity towards more subtle limits. The most important thing is that a simple post-mortem uncovers so many truths about the system, that can be potentially be source of other bug(s). Here a good detective cleans the ecosystem rather than cleaning the system of only the brats under investigation. The detective is somewhat like Max Payne :).
Own what you do.
This one of the awesome wisdom community gives. What is yours is everybody's and what is everybody's is yours. You can get a software and can change components and make it like you own it. This is better than it reads. Any effort that is well enough as an enhancement in this customized system is well enough for the community as it traces back to it. The change might be expected / critical / or might be simple addon serving various other test cases. Either way it adds to the development cycle. VLC is one of the big successes mainly due to this.
Meet the Inspirers.
Opensource is filled with people loving, gentle and knowledge loving people. The kind of people fond of wildlife, photography, music and craftsmanship. Its a delight to know people with such personalities. Just as a matter of fact, I had been to FOSS.IN 2012 conference in Bangalore. I met with sebastian kugler (KDE Maintainer) (www.vizzzion.org)(http://www.behindkde.org/sebastian-k%C3%BCgler), Tobias Mueller (Gnome 3.6 Developer), Kushal Das (Fedora Developer), Lennart Poettering (systemd Maintainer), Gene Kogan, Kartik Mistry (Debian Maintainer), Ulrich Drepper (Former Fedora Contributer, currently works in GS). Each One of them had contributed to improve technology for themselves and others. It is pure magic that instills so much enthusiasm and inspiration.
Nobody is perfect
The Opensource evolved from mistakes of others. Though shortcomings of a software cannot be attributed to its developer, we get very important lessons of life. PATIENCE AND OPTIMISM. When u identify a bug and deploy a fix, you are actually bridging the gap of some other developer. And somebody might as well do it for you. We also infer from this fact, that the ready to use software is also buggy and we need to monitor and even deploy a fix if necessary. Living in this constant responsible and aware environment is a very important habit to get to.
Nothing is waste.
Somebody's leisure is anothers solution. GitHub, Launchpad, Sourceforge, Bitbucket are full of such small scale yet very useful softwares. A student makes some plugin for a software for disseration grades, ends up getting used by big time corporates, or better ends up being a complete full fledged software. Just as a peice of cloth ends up getting used up, so it software.
Proactive Participation
In opensource "Support" is a thing which is very rare. Proactive Participation in debugging, providing IRC help, Providing Documentations, Cheatsheets, Manuals are also important in software, which gives value addition. I feel very proud to see that majority of reasonably highly used softwares have nice documentation to help people use. Ops Software in particular usually have a very frequent discussions in IRC confrooms and forums, where developers learn about users facing problems and provide help to configuration and use using their expertise. Platforms like stackexchange help in tagging and categorising such expertise.
With all these points i hope adopting opensource instill good values in your life too.
Friday, January 18, 2013
A Meeting with Gene Kogan
Take a look at: http://hasgeek.tv/fossdotin/2012-1/114-gene-kogan-hackernote-day-1-how-open-source-software-has-upended-art
Gene, is an artist, an opensource hacktivisit. Find him in genekogan.com. He blasted the hackernote session on DAY1 at Foss.in, at Bangalore. This guy loves art and is persuing a line of creating art with http://openprocessing.org/. He calls himself a Applied Mathamatics Guy and not a S/W Developer, but he definitely boggles out better s/w developers.
https://github.com/genekogan/
The Next Day i met him personally at the hackspace. To Discuss the Logger Tool he created for logging his day to day life. https://github.com/genekogan/logger
I actually started corresponding to him regarding suggestions and how it can be converted into a nice piece of service and a social media platform. Though insisted on the fact that he required nothing more than a way to log his life. But he was so happy that somebody had shown interest in his work and was willing to work in this venture. He was open to all changes, also told about the list of changes he is gonna release in coming days.
This guy is an example of what i liked to be, what i used to be. It is fun writing softwares to address own problems rather than problems of the mass domain and big corporates. Its so much fun, when u are the user of your own software. I wish him good luck in future endeavors with a hope to work full time with him someday.
Monday, November 5, 2012
SETTING UP RAID 5 ON CLOUD / Amazon Linux. EC2
Few Days Back i was asked to optimize one of the elastic Search Node. I Identified one of the BottleNecks in DISKIO. Went to solve it with 5 disk with 4 stripes and 1 parity.
SETTING RAID LEVEL 5
INSTANCE
~$ ec2-describe-instances | grep XX.XX.XX.XXX INSTANCE i-axxxxxxx ami-0xxxxxxx running Pradeep-Keys 0 m1.large 2012-10-30T11:44:20+0000 us-east-1c monitoring-disabled XXXX vpc-sdsd2 subnet-1dsdsdsd ebs paravirtual xen sCFML1351596348533 sg-a99f80c5, sg-7ea0bf12 default false NIC eni-4c1sdsds7 subnet-1dsdsd vpc-sdsd2 323323244233 in-use XX.XX.XX.XXX true PRIVATEIPADDRESS XX.XX.XX.XXX
CREATING DISKS
~$ ec2-create-volume -s 128 -z us-east-1c VOLUME vol-0 128 us-east-1c creating 2012-11-05T09:50:30+0000 standard ~$ ec2-create-volume -s 128 -z us-east-1c VOLUME vol-4 128 us-east-1c creating 2012-11-05T09:51:08+0000 standard ~$ ec2-create-volume -s 128 -z us-east-1c VOLUME vol-1 128 us-east-1c creating 2012-11-05T09:51:13+0000 standard ~$ ec2-create-volume -s 128 -z us-east-1c VOLUME vol-5 128 us-east-1c creating 2012-11-05T09:51:17+0000 standard ~$ ec2-create-volume -s 128 -z us-east-1c VOLUME vol-8 128 us-east-1c creating 2012-11-05T09:51:22+0000 standard
ATTACH THE VOLUMES
saurajeet.d:~$ ec2-attach-volume vol-0 -i i-axxxxxxx -d sdf ATTACHMENT vol-0 i-axxxxxxx sdf attaching 2012-11-05T10:02:43+0000 saurajeet.d:~$ ec2-attach-volume vol-4 -i i-axxxxxxx -d sdg ATTACHMENT vol-4 i-axxxxxxx sdg attaching 2012-11-05T10:03:35+0000 saurajeet.d:~$ ec2-attach-volume vol-1 -i i-axxxxxxx -d sdh ATTACHMENT vol-1 i-axxxxxxx sdh attaching 2012-11-05T10:04:13+0000 saurajeet.d:~$ ec2-attach-volume vol-5 -i i-axxxxxxx -d sdi ATTACHMENT vol-5 i-axxxxxxx sdi attaching 2012-11-05T10:04:49+0000 saurajeet.d:~$ ec2-attach-volume vol-8 -i i-axxxxxxx -d sdj ATTACHMENT vol-8 i-axxxxxxx sdj attaching 2012-11-05T10:05:19+0000
STARTING THE RAID SERVICE
[saurajeet.d@es1 ~]$ sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=5 /dev/xvdf /dev/xvdg /dev/xvdh /dev/xvdi /dev/xvdj mdadm: layout defaults to left-symmetric mdadm: layout defaults to left-symmetric mdadm: chunk size defaults to 512K mdadm: layout defaults to left-symmetric mdadm: layout defaults to left-symmetric mdadm: layout defaults to left-symmetric mdadm: layout defaults to left-symmetric mdadm: size set to 134216192K mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started. [saurajeet.d@es1 ~]$
SET THE ARRAY TO START AT BOOT, THEREBY POPULATING THE CONF FILE
[saurajeet.d@es1 ~]$ sudo mdadm --detail --scan ARRAY /dev/md0 metadata=1.2 spares=1 name=0 UUID=e47f9d29:cf9f0299:e2305a7c:0d03d014 [saurajeet.d@es1 ~]$ sudo vim /etc/mdadm.conf [saurajeet.d@es1 ~]$ cat /etc/mdadm.conf DEVICE /dev/xvd[f-j] ARRAY /dev/md0 metadata=1.2 spares=1 name=0 UUID=e47f9d29:cf9f0299:e2305a7c:0d03d014
SET READAHEAD BUFFER TO 65K
[saurajeet.d@es1 ~]$ sudo blockdev --setra 65536 /dev/md0 [saurajeet.d@es1 ~]$
DEFAULT BLOCK SIZE TAKEN WAS
[saurajeet.d@es1 ~]$ cat /sys/block/md0/queue/physical_block_size 512
CREATING FILE SYSTEM ONTO THE ARRAY
[saurajeet.d@es1 ~]$ sudo mkfs.xfs /dev/md0 log stripe unit (524288 bytes) is too large (maximum is 256KiB) log stripe unit adjusted to 32KiB meta-data=/dev/md0 isize=256 agcount=16, agsize=8388480 blks = sectsz=512 attr=2 data = bsize=4096 blocks=134215680, imaxpct=25 = sunit=128 swidth=512 blks naming =version 2 bsize=4096 ascii-ci=0 log =internal log bsize=4096 blocks=65536, version=2 = sectsz=512 sunit=8 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0You can calculate optimal options using a calculator here: http://uclibc.org/~aldot/mkfs_stride.html in case u r using ext based file systems
You can also use tune2fs to tune out the filesystem options past this point.
BUILDING RAID
[saurajeet.d@es1 ~]$ sudo cat /proc/mdstat Personalities : [raid6] [raid5] [raid4] md0 : active raid5 xvdj[5] xvdi[3] xvdh[2] xvdg[1] xvdf[0] 536864768 blocks super 1.2 level 5, 512k chunk, algorithm 2 [5/4] [UUUU_] [====>................] recovery = 22.1% (29781288/134216192) finish=125.9min speed=13822K/sec unused devices: <none>
YOU CAN CHECK THE HEALTH OF THE ARRAY
[saurajeet.d@es1 ~]$ sudo mdadm --detail /dev/md0 /dev/md0: Version : 1.2 Creation Time : Mon Nov 5 10:19:55 2012 Raid Level : raid5 Array Size : 536864768 (511.99 GiB 549.75 GB) Used Dev Size : 134216192 (128.00 GiB 137.44 GB) Raid Devices : 5 Total Devices : 5 Persistence : Superblock is persistent
Update Time : Mon Nov 5 11:00:47 2012 State : clean, degraded, recovering Active Devices : 4 Working Devices : 5 Failed Devices : 0 Spare Devices : 1
Layout : left-symmetric Chunk Size : 512K
Rebuild Status : 30% complete
Name : 0 UUID : e47f9d29:cf9f0299:e2305a7c:0d03d014 Events : 9
Number Major Minor RaidDevice State 0 202 80 0 active sync /dev/sdf 1 202 96 1 active sync /dev/sdg 2 202 112 2 active sync /dev/sdh 3 202 128 3 active sync /dev/sdi 5 202 144 4 spare rebuilding /dev/sdj
NOW THAT THE RAID BUILDUP IS DONE. IF NOT WAIT TILL `cat /proc/mdstat` shows out 100% rebuilt
We have a potential problem. All storage devices are booted during the kernel loading process. Sometimes errors occur which involves the md0 to rename to md127 or some number. That is because Software RAID is a kernel module which needs takes time out of the running kernel and this missing timeline to do unexpected results. We solve this problem by putting mdadm.conf to the ramfs.ramfs is a vital peice of information for booting. Any Fuckup may render the system unbootable.
NOTICE MATCHING VMLINUZ AND INITRD VERSION NUMBERS
[saurajeet.d@es1 ~]$ cd /boot [saurajeet.d@es1 boot]$ ls config-3.2.21-1.32.6.amzn1.x86_64 grub initramfs-3.2.21-1.32.6.amzn1.x86_64.img System.map-3.2.21-1.32.6.amzn1.x86_64 vmlinuz-3.2.21-1.32.6.amzn1.x86_64 [saurajeet.d@es1 boot]$ lsinitrd initramfs-3.2.21-1.32.6.amzn1.x86_64 | grep mdadm.conf [saurajeet.d@es1 boot]NOTICE NO FILE CALLED MDADM.CONF found. WE NEED TO INCLUDE THIS FILE USING THE DRACUT FACILITY.
[root@es1 boot]# cp initramfs-3.2.21-1.32.6.amzn1.x86_64.img initramfs-3.2.21-1.32.6.amzn1.x86_64.img.1 [root@es1 boot]# dracut "initramfs-$(uname -r).img" $(uname -r) E: Will not override existing initramfs (/boot/initramfs-3.2.21-1.32.6.amzn1.x86_64.img) without --force [root@es1 boot]# dracut "initramfs-$(uname -r).img" $(uname -r) --force E: Will not override existing initramfs (/boot/initramfs-3.2.21-1.32.6.amzn1.x86_64.img) without --force [root@es1 boot]# ls -l initramfs-3.2.21-1.32.6.amzn1.x86_64.img -rw-r--r-- 1 root root 5955095 Jun 25 22:51 initramfs-3.2.21-1.32.6.amzn1.x86_64.img [root@es1 boot]# rm initramfs-3.2.21-1.32.6.amzn1.x86_64.img rm: remove regular file `initramfs-3.2.21-1.32.6.amzn1.x86_64.img'? y [root@es1 boot]# dracut "initramfs-$(uname -r).img" $(uname -r) [root@es1 boot]# ls -l total 18684 -rw-r--r-- 1 root root 60125 Jun 23 02:34 config-3.2.21-1.32.6.amzn1.x86_64 drwxr-xr-x 2 root root 4096 Sep 4 12:14 grub -rw-r--r-- 1 root root 8963954 Nov 5 14:35 initramfs-3.2.21-1.32.6.amzn1.x86_64.img -rw-r--r-- 1 root root 5955095 Nov 5 14:32 initramfs-3.2.21-1.32.6.amzn1.x86_64.img.1 -rw------- 1 root root 1402139 Jun 23 02:34 System.map-3.2.21-1.32.6.amzn1.x86_64 -rwxr-xr-x 1 root root 2739088 Jun 23 02:34 vmlinuz-3.2.21-1.32.6.amzn1.x86_64 [root@es1 boot]# sudo reboot^C [root@es1 boot]# lsinitrd initramfs-3.2.21-1.32.6.amzn1.x86_64.img | grep mdadm -rwxr-xr-x 1 root root 451344 Mar 16 2012 sbin/mdadm -rwxr-xr-x 1 root root 106 Jan 6 2012 sbin/mdadm_auto -rw-r--r-- 1 root root 106 Nov 5 10:23 etc/mdadm.confYou can try
draconf mdadmconf="{yes|no}"
if the dracut execution still doesnt include mdadm.confREBOOT AND TEST
saurajeet@saurajeet-THX:~$ ssh 10.10.XX.XXXX Last login: Mon Nov 5 13:42:42 2012 from XX.XX.XX.XXX
__| __|_ ) _| ( / Amazon Linux AMI ___|\___|___|
https://aws.amazon.com/amazon-linux-ami/2012.03-release-notes/ There are 30 security update(s) out of 167 total update(s) available Run "sudo yum update" to apply all updates. Amazon Linux version 2012.09 is available. [saurajeet.d@es1 ~]$ ls /dev/md md/ md0 [saurajeet.d@es1 ~]$ cat /proc/mdstat Personalities : [raid6] [raid5] [raid4] md0 : active raid5 xvdh[2] xvdj[5] xvdf[0] xvdi[3] xvdg[1] 536864768 blocks super 1.2 level 5, 512k chunk, algorithm 2 [5/5] [UUUUU] unused devices: <none> [saurajeet.d@es1 ~]$ sudo mdadm -D /dev/md0 /dev/md0: Version : 1.2 Creation Time : Mon Nov 5 10:19:55 2012 Raid Level : raid5 Array Size : 536864768 (511.99 GiB 549.75 GB) Used Dev Size : 134216192 (128.00 GiB 137.44 GB) Raid Devices : 5 Total Devices : 5 Persistence : Superblock is persistent
Update Time : Mon Nov 5 13:03:33 2012 State : clean Active Devices : 5 Working Devices : 5 Failed Devices : 0 Spare Devices : 0
Layout : left-symmetric Chunk Size : 512K
Name : 0 UUID : e47f9d29:cf9f0299:e2305a7c:0d03d014 Events : 26
Number Major Minor RaidDevice State 0 202 80 0 active sync /dev/sdf 1 202 96 1 active sync /dev/sdg 2 202 112 2 active sync /dev/sdh 3 202 128 3 active sync /dev/sdi 5 202 144 4 active sync /dev/sdj [saurajeet.d@es1 ~]$
TROUBLE SHOOT
If the RAID is not builtup during the bootup time. We may try mdadm -I which is script to automatically assemble raid from configuration files. If it fails for some reason lookup mdadm -As (Assemble and Scan), which does a manual scanning for drives to get a RAID timestamp and attempts rebuilding from there.COMPLETE THE SETUP WITH MOUNTING
[saurajeet.d@es1 ~]$ sudo cat /etc/fstab # LABEL=/ / ext4 defaults,noatime 1 1 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/sda3 none swap sw,comment=cloudconfig 0 0 /dev/md0 /data auto defaults,noatime 0 0
MOUNT
[saurajeet.d@es1 ~]$ sudo mkdir /data [saurajeet.d@es1 ~]$ sudo mount /dev/md0
[saurajeet.d@es1 ~]$ ls /data -l total 0 [saurajeet.d@es1 ~]$ mount /dev/xvda1 on / type ext4 (rw,noatime) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) /dev/md0 on /data type xfs (rw,noatime) [saurajeet.d@es1 ~]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 8.0G 1.1G 6.9G 14% / tmpfs 3.7G 0 3.7G 0% /dev/shm /dev/md0 512G 33M 512G 1% /data [saurajeet.d@es1 ~]$
WHY 512G
Capacity of RAID = Smin * (n - 1) => 128G * (5 -1) => 128G * 4 => 512GFOLLOW UPS
http://www.tldp.org/HOWTO/Software-RAID-HOWTO-5.htmlhttp://en.wikipedia.org/wiki/Standard_RAID_levels#RAID_5
http://zackreed.me/articles/38-software-raid-5-in-debian-with-mdadm
https://bugzilla.redhat.com/show_bug.cgi?id=606481
https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sec-Verifying_the_Initial_RAM_Disk_Image.html
FUTURE TASKS
CANT INCUDE CODE FOR AMAZON CLOUD FORMATION. You KNOW WHY, Happy RAIDING
Monday, February 28, 2011
Autocomplete using javascript.
Save the following code as an html file and run it in any browser
CODE
<!--AUTOCOMPLETE DEMONSTATION BY SAURAJEET DUTTA
Birla Institute Of Technology, Mesra, Ranchi
Feb 28, 2011
This code is only made to test the autocompleting procedure from one word "saurajeet"
this code has to be modified for a list of word...
-->
<script type="text/javascript">
document.onkeyup = KeyCheck;
function KeyCheck(e)
{
var KeyID = (window.event) ? event.keyCode : e.keyCode;
switch(KeyID)
{
case 13: if (document.getElementById("suggest").innerHTML == "<no suggest>")
break;
else
{ document.getElementById("typepad").value = document.getElementById("suggest").innerHTML;
return;
}
}
}
function suggest(str)
{ document.getElementById("ff").innerHTML = str.length;
var suggest = "saurajeet";
if (matched (suggest, str))
{ document.getElementById("suggest").innerHTML = suggest;
}
else
{ document.getElementById("suggest").innerHTML = "<no suggest>";
}
return;
}
function matched (a, b)
{ if (b.length < 4)
{ return false;
}
for (var i = 0; i < b.length; i++)
{ if (a[i] != b[i])
return false;
}
return true;
}
</script>
<input type="text" name="MyText" id='typepad' onkeyup="suggest(this.value)" onchange="" />
<strong id="ff">0</strong>
<strong>, Suggestive Text </strong> <label id="suggest">No Suggestion</label>
<pre>
1. Enter the string "saur" into the textbox
2. Once the suggestive Text changes Appears in
3. press enter to complete the string
Note: This code is only made with to work with one word change the program accordingly for a list of words..
HOPE I HAVE FULFILLED SOME OF YOUR EXPECTATIONS
</pre>
Monday, June 7, 2010
My hbagh. trip for DSS analysis
Hi, i am currently doing a summer project on a DSS. We are designing this for a local company. You might not expect much of my photographs as i was the one taking them.
I really enjoyed the trip. These are some of the snaps to cherish.
We in the hostel ready for taking the trip. I, Ganesh [left] and RKS[right]. At least we are the permanent members.
Walking by the countryside and hoping that our ride from BIT more does not be late. We had a walk of at least 30 minutes.
We got the ride but very late. The chauffeur woke up late. I don't understand, these chauffeurs sleep all day in their vehicle and still needs the night for sleeping, had i been a chauffer, i would have gone to strip clubs at nights. That snoring bastard kept us waiting in that heat for 90 minutes. Any way the journey is on.
You now came the humpy bumpy. In the highway connecting the hbagh. and ranchi, there is a coalmine which is on fire. The fire recently emerged in the road that caused the vehicles to either take a long route or a short route from the woods. As usual we chose to see the short one. That is through the woods. though the route was somewhat bumpy but was filled with natural beauty.
At last, we reached the destination.
The office of e-nibandhan, Jharkhand Automated Registration System (JARS), Department of Information Technology, Government of Jharkhand. SRO – Hazaribagh.
[Look at the serious people, working]
We were enquiring the employers about the operation in practice. We were killing their precious time. Most importantly we got full support from the very employers in building something that is going to make their professional life miserable in the future.
Our work was over in an about 1 hr or so, we were lucky to have less crowd and our question answer session was smooth.
Mr. Manish, the divisional head [not included in the photo] was of great help along with above operators. Their experience in this matter was unmatched and the speed of executing an ORD was unexpectedly awesome with accuracy.
We had prepared a list of question to ask. All were answered in a very detailed way with example. And an ORD was processed in front of us to make sure that we get the process.
At last we are back at Mesra.
Wednesday, February 3, 2010
Operating System Lab Practicals
2 processes ‘A’ and ‘B’ consist of an alternating sequence of CPU burst and IO burst. Each burst is of 1 second duration. There are 10 CPU burst and 9 IO burst in each job. If job ‘A’ runs first than job ‘B’, how much time does is take to run the two jobs ‘A’ and ‘B’.
How much time will the job ‘A’ take for completion?
How much time will job ‘B’ take for completion?
How much time does the CPU remains idle?
What is the percentage utilization of CPU?
If two jobs are multi-programmed we start with job A. How much time will it take?
/* CALCULATING THE TIME TAKEN BY THE TWO PROCESSES
* AUTHOR : Saurajeet Dutta
* EMAIL : <vention.gothics> AT <gmail> DOT COM
* DATE : JAN 26 2010
* INSTITUTE : Birla Institute of Technology, Mesra
* LICENSE : FREE (as in freedom not as in beer)
* THE COMPILATION USES POSIX THREADING LIBRARIES.
* DEVELOPED IN openSuSE 11.2
*/
#include <stdio.h>
#include <pthread.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
//MACRO SECTION
#define SINGLE_PROGRAMMING 0
#define MULTI_PROGRAMMING 1
//END MACRO SECTION
//GLOBAL VARIABLE
unsigned short cpu_timeA = 0;
unsigned short cpu_timeB = 0;
unsigned short io_timeA = 0;
unsigned short io_timeB = 0;
//END GLOBAL VARIABLE
typedef struct
{ unsigned short thread_id;
bool mode;
} thread_control_block;
void * fnA (void * tcbA)
{ thread_control_block *myTCB;
unsigned short cpu_burst= 10;
unsigned short io_burst = 9;
unsigned long localCtr = 0;
int dummy, i;
myTCB = (thread_control_block *) tcbA;
if (myTCB->mode == SINGLE_PROGRAMMING)
{ for (localCtr = 0; localCtr < cpu_burst; localCtr++)
{ cpu_timeA++;
}
for (localCtr = 0; localCtr < io_burst; localCtr++)
{ io_timeA++;
}
}
if (myTCB->mode == MULTI_PROGRAMMING)
{ //CPU burst
for (localCtr = 0; localCtr < 800000000; localCtr++)
{}
sleep(9);
}
}
void * fnB (void * tcbB)
{ int dummy, i;
thread_control_block * myTCB;
unsigned short cpu_burst= 10;
unsigned short io_burst = 9;
unsigned long localCtr = 0;
myTCB = (thread_control_block *) tcbB;
if (myTCB->mode == SINGLE_PROGRAMMING)
{ for (localCtr = 0; localCtr < cpu_burst; localCtr++)
{ cpu_timeB++;
}
for (localCtr = 0; localCtr < io_burst; localCtr++)
{ io_timeB++;
}
}
if (myTCB->mode == MULTI_PROGRAMMING)
{ sleep (9);
for (localCtr = 0; localCtr < 800000000; localCtr++) //an average machine takes about 10s of cpu burst to compute this loop
{}
}
}
int main (void)
{ pthread_t threadA, threadB;
int retCode = 0;
int total_time = 0;
float eff = 0;
time_t time1, time2;
//create thread control block
thread_control_block tcb1;
thread_control_block tcb2;
tcb1.thread_id = 1;
tcb1.mode = SINGLE_PROGRAMMING;
tcb2.thread_id = 2;
tcb2.mode = SINGLE_PROGRAMMING;
//entering single programming mode
fnA ((void *) &tcb1);
fnB ((void *) &tcb2);
//analysing results
total_time = cpu_timeA + io_timeA;
printf ("\n\n\tSINGLE PROGRAMMING\n\tThe total time taken by process A is %d\n", total_time);
printf ("\tCPU time for A is %d\n", cpu_timeA);
printf ("\tIO time for A is %d\n", io_timeA);
printf ("\tCPU idle time for A is %d\n\n", total_time - cpu_timeA);
total_time = cpu_timeB + io_timeB;
printf ("\tThe total time taken by process B is %d\n",total_time);
printf ("\tCPU time for B is %d\n", cpu_timeB);
printf ("\tIO time for B is %d\n", io_timeB);
printf ("\tCPU idle time for B is %d\n", total_time - cpu_timeB);
eff = cpu_timeA + cpu_timeB;
eff /= cpu_timeA + cpu_timeB + io_timeA + io_timeB;
eff *= 100;
printf ("\n CPU EFFICIENCY [SINGLE PROGRAMMING] : %f\n", eff);
//creating thread a;
tcb1.mode = MULTI_PROGRAMMING;
tcb2.mode = MULTI_PROGRAMMING;
time (&time1);
retCode = pthread_create (&threadA, NULL, fnA, (void *)&tcb1);
if (retCode < 0)
{ printf ("Error in creating the thread.\n");
pthread_exit(NULL);
return EXIT_FAILURE;
}
//creating thread b
retCode = pthread_create (&threadB, NULL, fnB, (void *)&tcb2);
if (retCode < 0)
{ printf ("Error in creating thread B.\n");
pthread_exit(NULL);
return EXIT_FAILURE;
}
pthread_join (threadB, NULL);
time(&time2);
printf ("The total time taken for execution of 2 threads is: %d", time2 - time1);
eff = 20;
eff /= (time2 - time1 + 1);
eff *= 100;
printf ("\n\n\t CPU EFFICIENCY [MULTITASKING]: %f\n", eff);
return EXIT_SUCCESS;
}












