Advertisement
Tusohian

OS Test

Dec 11th, 2018
962
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ==========
  2. Best Fit
  3. ==========
  4.  
  5. #include<stdio.h>
  6.  
  7. void main()
  8. {
  9.     int fragment[20],b[20],p[20],i,j,nb,np,temp,lowest=9999;
  10.     static int barray[20],parray[20];
  11.  
  12.  
  13.     printf("\nEnter the number of blocks:");
  14.     scanf("%d",&nb);
  15.     printf("Enter the number of processes:");
  16.     scanf("%d",&np);
  17.  
  18.     printf("\nEnter the size of the blocks:-\n");
  19.     for(i=1;i<=nb;i++)
  20.     {
  21.         printf("Block no.%d:",i);
  22.         scanf("%d",&b[i]);
  23.     }
  24.  
  25.     printf("\nEnter the size of the processes :-\n");
  26.     for(i=1;i<=np;i++)
  27.     {
  28.         printf("Process no.%d:",i);
  29.         scanf("%d",&p[i]);
  30.     }
  31.  
  32.     for(i=1;i<=np;i++)
  33.     {
  34.         for(j=1;j<=nb;j++)
  35.         {
  36.             if(barray[j]!=1)
  37.             {
  38.                 temp=b[j]-p[i];
  39.                 if(temp>=0)
  40.                     if(lowest>temp)
  41.                     {
  42.                         parray[i]=j;
  43.                         lowest=temp;
  44.                     }
  45.             }
  46.         }
  47.  
  48.         fragment[i]=lowest;
  49.         barray[parray[i]]=1;
  50.         lowest=10000;
  51.     }
  52.  
  53.     printf("\nProcess_no\tProcess_size\tBlock_no\tBlock_size\tFragment");
  54.     for(i=1;i<=np && parray[i]!=0;i++)
  55.         printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,p[i],parray[i],b[parray[i]],fragment[i]);
  56. }
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. ==========================
  64. First Fit
  65. ==========================
  66.  
  67. ...http://world-of-c-programming.blogspot.com/2012/11/first-fit-memory-management-algorithm.html
  68.  
  69.  
  70. #include<stdio.h>
  71. #include<conio.h>
  72. #define max 25
  73.  
  74. void main()
  75. {
  76.     int frag[max],b[max],f[max],i,j,nb,nf,temp;
  77.     static int bf[max],ff[max];
  78.  
  79.     printf("\n\tMemory Management Scheme - First Fit");
  80.     printf("\nEnter the number of blocks:");
  81.     scanf("%d",&nb);
  82.     printf("Enter the number of files:");
  83.     scanf("%d",&nf);
  84.     printf("\nEnter the size of the blocks:-\n");
  85.     for(i=1; i<=nb; i++)
  86.     {
  87.         printf("Block %d:",i);
  88.         scanf("%d",&b[i]);
  89.     }
  90.     printf("Enter the size of the files :-\n");
  91.     for(i=1; i<=nf; i++)
  92.     {
  93.         printf("File %d:",i);
  94.         scanf("%d",&f[i]);
  95.     }
  96.  
  97.     for(i=1; i<=nf; i++)
  98.     {
  99.         for(j=1; j<=nb; j++)
  100.         {
  101.             if(bf[j]!=1)
  102.             {
  103.                 temp=b[j]-f[i];
  104.                 if(temp>=0)
  105.                 {
  106.                     ff[i]=j;
  107.                     break;
  108.                 }
  109.             }
  110.         }
  111.         frag[i]=temp;
  112.         bf[ff[i]]=1;
  113.     }
  114.     printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
  115.     for(i=1; i<=nf; i++)
  116.         printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
  117.     getch();
  118. }
  119.  
  120.  
  121.  
  122.  
  123. ==========================
  124. Worst Fit
  125. ==========================
  126.  
  127. #include<stdio.h>
  128. #include<conio.h>
  129. #define max 25
  130.  
  131. void main()
  132. {
  133.  int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
  134.  static int bf[max],ff[max];
  135.  clrscr();
  136.  
  137.  printf("\n\tMemory Management Scheme - Worst Fit");
  138.  printf("\nEnter the number of blocks:");
  139.  scanf("%d",&nb);
  140.  printf("Enter the number of files:");
  141.  scanf("%d",&nf);
  142.  printf("\nEnter the size of the blocks:-\n");
  143.  for(i=1;i<=nb;i++) {printf("Block %d:",i);scanf("%d",&b[i]);}
  144.  printf("Enter the size of the files :-\n");
  145.  for(i=1;i<=nf;i++) {printf("File %d:",i);scanf("%d",&f[i]);}
  146.  
  147.  for(i=1;i<=nf;i++)
  148.  {
  149.   for(j=1;j<=nb;j++)
  150.   {
  151.    if(bf[j]!=1)    //if bf[j] is not allocated
  152.    {
  153.     temp=b[j]-f[i];
  154.     if(temp>=0)
  155.     if(highest<temp)
  156.     {
  157.      ff[i]=j;
  158.      highest=temp;
  159.     }
  160.    }
  161.   }
  162.   frag[i]=highest;
  163.   bf[ff[i]]=1;
  164.   highest=0;
  165.  }
  166.  printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
  167.  for(i=1;i<=nf;i++)
  168.  printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
  169.  getch();
  170. }
  171.  
  172.  
  173.  
  174.  
  175. ================
  176. MFT
  177. ================
  178. #include<stdio.h>
  179. #include<conio.h>
  180. main()
  181. {
  182.     int mems, bls, nobl, extf,n, mp[10],intf=0;
  183.     int i,p=0;
  184.     printf("Enter the total memory  ");
  185.     scanf("%d",&mems);
  186.  
  187.     printf("Enter the block size  ");
  188.     scanf("%d", &bls);
  189.     nobl=mems/bls;
  190.     extf=mems - nobl*bls;
  191.  
  192.     printf("\nEnter the number of processes  ");
  193.     scanf("%d",&n);
  194.  
  195.     for(i=0; i<n; i++)
  196.     {
  197.         printf("Enter memory required for process %d  ",i+1);
  198.         scanf("%d",&mp[i]);
  199.     }
  200.     printf("\nNo. of Blocks available in memory  %d",nobl);
  201.     printf("\n\nPROCESS\tMEMORY REQUIRED\t ALLOCATED\tINTERNAL FRAGMENTATION");
  202.     for(i=0; i<n && p<nobl; i++)
  203.     {
  204.         printf("\n %d\t\t%d",i+1,mp[i]);
  205.         if(mp[i] > bls)
  206.             printf("\t\tNO\t\t---");
  207.         else
  208.         {
  209.             printf("\t\tYES\t%d",bls-mp[i]);
  210.             intf = intf + bls-mp[i];
  211.             p++;
  212.         }
  213.     }
  214.     if(i<n)
  215.         printf("\nMemory is Full, Remaining Processes cannot be accomodated");
  216.     printf("\n\nTotal Internal Fragmentation is %d",intf);
  217.     printf("\nTotal External Fragmentation is %d",extf);
  218.     getch();
  219. }
  220.  
  221.  
  222.  
  223.  
  224.  
  225. ==========================
  226. Bash (Shell Scripting)
  227. ==========================
  228.  
  229. gub@cseit:~$ ld
  230. ld: no input files
  231. gub@cseit:~$ cd Documents
  232. gub@cseit:~/Documents$ mkdir Tushar
  233. gub@cseit:~/Documents$ cd Tushar
  234. gub@cseit:~/Documents/Tushar$ which bash >new.sh
  235. gub@cseit:~/Documents/Tushar$ ls
  236. new.sh
  237. gub@cseit:~/Documents/Tushar$ chmod +x new.sh
  238. gub@cseit:~/Documents/Tushar$ gedit new.sh
  239. gub@cseit:~/Documents/Tushar$ gedit new.sh
  240. gub@cseit:~/Documents/Tushar$ /new.sh
  241. bash: /new.sh: No such file or directory
  242. gub@cseit:~/Documents/Tushar$ ./new.sh
  243.  
  244.  
  245.  
  246. #!/bin/bash
  247. echo -n "enter a number"
  248. read n
  249. for ((i=1;i<=n; i++))
  250. do
  251. echo "Output $i"
  252. done
  253.  
  254. ---------------------------------
  255.  
  256. #!/bin/bash
  257. echo -n "enter a number"
  258. read n
  259. sum=0
  260. for ((i=1;i<=n; i++))
  261. do
  262. sum=$((sum+i))
  263. done
  264. echo "Output is $sum"
  265.  
  266. ----------------------------
  267.  
  268.  
  269.  
  270. Taking input in array :
  271. >>>>>>>>>>>>>>>>>>>>>>
  272.  
  273. #!/bin/bash
  274. echo -n "enter limit: "
  275. read n
  276. echo "Enter Numbers: "
  277. for ((i=0;i<n; i++))
  278. do
  279. read a[$i]
  280. done
  281.  
  282.  
  283. ##!/bin/bash
  284. echo -n "enter limit: "
  285. read n
  286. echo "Enter Numbers: "
  287.  
  288. #!/bin/bash
  289.  echo "Enter the first number :"
  290. read a
  291. echo "Enter the second number : "
  292. read b
  293.  
  294. if [ $a -gt $b ]
  295. then
  296. num=$a
  297. den=$b
  298. else
  299. num=$b
  300. den=$a
  301. fi
  302. r=`expr $num % $den`
  303.  
  304. while [ $r -ne 0 ]
  305. do
  306. num=$den
  307. den=$r
  308. r=`expr $num % $den`
  309. done
  310.  
  311. gcd=$den
  312. lcm=`expr $a \* $b / $gcd`
  313.  
  314. echo " The LCM of $a and $b is : $lcm"
  315. echo " The GCD of $a and $b is : $gcd"
  316.  
  317. leaf year...
  318.  
  319. echo "Enter Year:"
  320. read y
  321.  
  322. year=$y
  323.  
  324. y=$(( $y % 4 ))
  325. if [ $y -eq 0 ]
  326. then
  327.     echo "$year is Leap Year!"
  328. else
  329.     echo "$year is not a Leap Year!"
  330. fi
  331.  
  332.  
  333.  
  334.  
  335. prime number...
  336.  
  337. echo "Enter a number: "
  338. read num
  339. i=2
  340. f=0
  341. while [ $i -le `expr $num / 2` ]
  342. do
  343. if [ `expr $num % $i` -eq 0 ]
  344. then
  345. f=1
  346. fi
  347. i=`expr $i + 1`
  348. done
  349. if [ $f -eq 1 ]
  350. then
  351. echo "The number is composite"
  352. else
  353. echo "The number is Prime"
  354. fi
  355.  
  356. Armstrong number or not...
  357. echo "Enter a number: "
  358. read c
  359.  
  360. x=$c
  361. sum=0
  362. r=0
  363. n=0
  364. while [ $x -gt 0 ]
  365. do
  366. r=`expr $x % 10`
  367. n=`expr $r \* $r \* $r`
  368. sum=`expr $sum + $n`
  369. x=`expr $x / 10`
  370. done
  371.  
  372. if [ $sum -eq $c ]
  373. then
  374. echo "It is an Armstrong Number."
  375. else
  376. echo "It is not an Armstrong Number."
  377. fi
  378.  
  379. factorial number....
  380. echo "Enter a number"
  381. read num
  382.  
  383. fact=1
  384.  
  385. while [ $num -gt 1 ]
  386. do
  387.   fact=$((fact * num))  #fact = fact * num
  388.   num=$((num - 1))      #num = num - 1
  389. done
  390.  
  391. echo $fact
  392.  
  393.  
  394.  
  395. palindrome.....
  396. echo "enter the string "
  397. read name
  398. name1=$(echo $name | rev)
  399. if [ $name = $name1 ]
  400. then
  401. echo "$name is palindrome"
  402. else
  403. echo "$name is not a palindrome"
  404. fi
  405.  
  406. sum of natural ...
  407.  echo "Sum of n natural numbers \n”
  408. echo "Enter the value of n "
  409. read n
  410. i = 0
  411. sum = 0
  412. while[$i –lt $n]
  413. do
  414. sum=’expr $sum + expr $i’
  415. i = ‘expr $i + 1’
  416. done
  417. echo "Sum of n natural numbers are : $sum”
  418.  
  419. #shell script to check whether a number is positive or negative
  420.  
  421. echo "Enter a Number"
  422. read num
  423.  
  424. if [ $num -lt 0 ]
  425. then
  426.     echo "Negative"
  427. elif [ $num -gt 0 ]
  428. then
  429.     echo "Positive"
  430. else
  431.     echo "Neither Positive Nor Negative"
  432. fi
  433.  
  434. odd or even....
  435. echo -n "Enter numnber : "
  436. read n
  437.  
  438. rem=$(( $n % 2 ))
  439.  
  440. if [ $rem -eq 0 ]
  441. then
  442.   echo "$n is even number"
  443. else
  444.   echo "$n is odd number"
  445. fi
  446.  
  447. addition using loop....
  448. n=$1
  449. result=0
  450. j=0
  451.  
  452. ADD(){
  453.     result=`expr $result + $j`
  454. }
  455.  
  456. #for (( i=1; i<=$n; i++ ))
  457. for i in {0..$n..1}
  458. do
  459.     ADD
  460.     j=`expr $j + $1`
  461. done
  462.  
  463. echo $result
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470. …….
  471. #!/bin/bash
  472.  
  473. num1=1
  474. num2=10
  475. if [ $num1 -gt $num2 ]; then
  476.                echo "number  one is greather  "
  477. else
  478.          echo "number two is greater"
  479. fi
  480.  
  481.  
  482. @for comapre  number
  483. ...................................
  484. #!/bin/bash
  485.  
  486. num1=1
  487. num2=10
  488. if [ $num1 -eq $num2 ]; then
  489.                echo "number  is equel  "
  490. else
  491.          echo "not equel"
  492. fi
  493.  
  494. @for check odd or even number
  495. ......................
  496. #!/bin/bash
  497.  
  498. echo -n "please enter a number"
  499. read n
  500. check=$(($n % 2))
  501. if [ $check -eq 0 ];then
  502. echo "$n is an even number"
  503. else
  504. echo "$n is an odd number"
  505. fi;
  506. -------------------------------
  507. @for string comparisom
  508.  
  509.  
  510. #!/bin/bash
  511.  
  512. num1="jahid"
  513. num2="arif"
  514. if [ $num1 = $num2 ]; then
  515.                echo "name is equal  "
  516. else
  517.          echo "not equal"
  518. fi
  519. -----------------------
  520. @FOR counting
  521.  
  522. #!/bin/bash
  523.  
  524. COUNT=6
  525. while [ $COUNT -gt 0 ]; do
  526. echo value of count is: $COUNT
  527. let COUNT=COUNT-1
  528. done
  529. ----------------
  530. @ for reverse
  531. #!/bin/bash
  532.  
  533. COUNT=1
  534. while [ $COUNT -lt 7 ]; do
  535. echo value of count is: $COUNT
  536. let COUNT=COUNT+1
  537. done
  538.  
  539. -----------------------
  540. #!/bin/bash
  541.  
  542. COUNT=0
  543. until [ $COUNT -gt 5 ]; do
  544. echo value of count is: $COUNT
  545. let COUNT=COUNT+1
  546. done
  547. @ addition
  548.  
  549. echo '#### let ###'
  550. let addition=3+5
  551. echo "3+5 =" $addition
  552.  
  553. @subtraction
  554.  
  555. echo '#### let ###'
  556. let subtraction=5-3
  557. echo $subtraction
  558.  
  559.  
  560. @power of
  561. echo '#### let ###'
  562. let poweroftwo=2**2
  563. echo "2^ 2=" $poweroftwo
  564.  
  565. @mathmatatics
  566.  
  567. echo 2^8 =$[ 2** 8 ]
  568.  
  569.  
  570.  
  571.  
  572. =====================
  573. Linux Commands
  574. =====================
  575.  
  576. cd > changing directory
  577.  
  578. ls > seeing list
  579.  
  580. clear > clearing terminal screen
  581.  
  582. cd -  >   backing a from directory
  583. cd ..  >  backing from a directory
  584.  
  585. cd ~   > jump to the home directory
  586.  
  587. mkdir  > making or creating new folder
  588.  
  589. rmdir  > removing or deleting a directory
  590.  
  591. mv > renaming a folder or file
  592.  
  593. touch  > creating a new file
  594.  
  595. rm  > removing a file
  596.  
  597. pwd > Shows the working directory name with path
  598.  
  599. (cat >file1.txt ) > Creating new file with contents
  600. ctrl+z > (to exit from editor of consents)
  601.  
  602. gedit fileName.extension  > for opening a specific file
  603.  
  604. ls b* > show the file list that starts with b and then one or more character
  605.  
  606. ls *l* > shows characters that has before and after some character before and after 'l'
  607.  
  608. ls ?l* > Shows the list that has 1 character before 'l' and one or more character after 'l'
  609.  
  610. ls [rt]*  > Shows the list that starts with 'r' and 't'
  611.  
  612. ls *[0-9]*    > Shows the list that contains numeric number (0-9)
  613.  
  614. ls [^a-k]*    > Shows the list that does not starts with "a" to "k".
  615.  
  616. head -4 ba.txt > shows the first 4 list from the file named ba.txt
  617.  
  618. tail -3 ba.txt > shows the last 3 list from the file named ba.txt
  619.  
  620. sort ba.txt > sort the contents alphabetically
  621.  
  622. nl ba.txt  > Shows the line number of the contents of the file
Advertisement
RAW Paste Data Copied
Advertisement