Wednesday, 16 January 2019

POSIX thread (pthread) System call program - ubuntu

The POSIX(Portable Operating system Interface) function is  to create a new thread within the same process used header file is
#include <pthread.h>

Program :
//POSIX Portable Operating System Interface called as pthread
#include<stdio.h>
#include<pthread.h>
#include<stdlib.h>

void *thread(void *arg);
int i,sum;

void main()
{
pthread_t tid;
printf("\n sum=%d",sum);
pthread_create(&tid,NULL,thread,NULL);
pthread_join(tid,NULL);
printf("\n sum=%d\n",sum);
}

void *thread(void *arg)
{
for(i=0;i<3;i++)
sum=sum+i;
pthread_exit(0);
}
 
Output: using this command we can execute the pthread system call programs
gcc pthread.c -o thread -lpthread
    

  • gcc is the compiler command.
  • thread.c is the name of c program source file.
  • -o is option to make object file.
  • thread is the name of object file.
  • -lpthread is option to execute pthread.h library file.
 
 

exec() System call program - ubuntu

/* program for execute system call  */
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>  // for datatypes
#include<sys/types.h> // for standard symbolic constants & types
int main(int argc, char *argv[])
{
    int ret;
    printf("\n the pid is %d \n",getpid());
    ret=execl("/bin/ls","ls","-l",NULL);  // path the command (ls -l )
    printf("failed process is %d",ret);
return 0;
}

output:

wait() System call program - ubuntu

/* Wait for child termination - wait.c */
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>  // standard symbolic constant & types
#include<sys/types.h> // for datatype
#include<sys/wait.h> // for wait system call
main()
{
  int i,pid;
  pid = fork();
  if(pid < 0)
  {
   printf("\nProcess creation failure\n"); exit(-1);
  }
  else if(pid > 0)
  {
   wait(NULL);
   printf ("\nParent starts\nEven Nos:");
   for (i=2;i<=10;i+=2)
   printf("%3d",i);
   printf("\nParent ends\n");
  }
  else if(pid == 0)
  {
   printf ("\nChild starts\nOdd Nos:");
   for (i=1;i<10;i+=2)
   printf ("%3d",i);
   printf ("\nChild ends\n");
  }
}
output:


Tuesday, 15 January 2019

fork() System call programs - ubuntu


/* Process creation - fork.c */
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>  // for datatypes
#include<sys/types.h> // for standard symbolic constants & types
void main()
{
  int x;
  x=fork();
  printf(" \n process pid =%d", getpid());
  printf(" \n returned value =%d\n", x);
}


output



/* Process creation - fork.c */
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>  // for datatypes
#include<sys/types.h> // for standard symbolic constants & types
void main()
{
 int x;
 x=fork();
 if(x == 0)
  {
   printf("\n\n CHILD PROCESS STARTS");
   printf(" \n process pid =%d", getpid());
   printf(" \n returned value =%d\n", x);
  }
 else
  {
   printf("\n\n PARENT PROCESS STARTS ");
   printf(" \n process pid =%d", getpid());
   printf(" \n returned value =%d\n", x);
  }
}

output



/* Process creation - fork.c */
#include<stdio.h>
#include<unistd.h>  // for datatypes
#include<sys/types.h> // for standard symbolic constants & types
void main()
 {
  int x=10;
    if(fork() == 0)
    {
             sleep(10);
            x=x+10;
            printf("\n from child =%d", x);
    }
    else
        printf("\n from parent =%d", x);
 }

output



/* Process creation - fork.c */
#include<stdio.h>
#include<unistd.h>  // for datatypes
#include<sys/types.h> // for standard symbolic constants & types
void main()
{
fork();
fork();
fork();
printf("\n Hi !");
}

output:

Introduction to System call programs on different process ids- ubuntu

/* program to illustrate different Process id */
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>  // for datatypes
#include<sys/types.h> // for standard symbolic constants & types
void main()
{
    int pid;
    printf("\n process id = %d", getpid());
    printf("\n parent process =%d", getppid());
    printf("\n group id=%d", getgid());
    printf("\n user id =%d\n", getuid());
}

output


Saturday, 12 January 2019

Steps to Install simple screen recoder in ubuntu operating system

How to Install Simple Screen Recorder in Ubuntu:

step1: Open terminal using shortcut keys(Ctrl+Alt+T) and then type the following commands

step 2: sudo add-apt-repository ppa:maarten-baert/simplescreenrecorder


step 3: sudo apt update

step 4:sudo apt install simplescreenrecorder simplescreenrecorder-lib

step 5: To record 32-bit OpenGL applications on a 64-bit system, run:
sudo apt install simplescreenrecorder-lib:i386


How to uninstall Simple Screen Recorder in Ubuntu:

 simply type the below command on the terminal:
sudo apt remove simplescreenrecorder simplescreenrecorder-lib

Friday, 11 January 2019

Steps to uninstall wine command in ubuntu operating system

Please follow the steps here to Uninstall WINE file in Ubuntu OS

step1 : Check by typing a command winecfg on u r terminal of Ubuntu 32-bit or 64-bit system
winecfg

step2 :If we want to add r remove files just like in windows we need to  Installing synaptic package manager  in ubuntu from ubuntu software


step 3 :Now launch synaptic package manager


step 4 : Now select the unwanted files which u want to delete permanently by write clicking on the selected file choose an option mark for complete removal

step 5: check u r wine whether uninstalled fully r not by typing winecfg on the terminal as shown below

Thursday, 10 January 2019

Steps to Execute an .exe file in Ubuntu Operations System

Please follow the steps here to Install WINE, so that we can run any .exe file in Ubuntu OS

step1 : Check if you have an Ubuntu 32-bit or 64-bit system
lscpu

step2 :for 64 bit ubuntu/Installing Wine from a Standard Ubuntu Repository (recommended)
sudo apt install wine64
[OR]
for 32 bit ubuntu
sudo apt install wine32

step 3 :
wine --version //To verify the version of Wine through the following command:

step 4 : TO Install Wine from the WineHQ Repository
To add i386 architecture before installing a 64-bit version of Wine
sudo dpkg --add-architecture i386

step 5 : Add the relevant repository from the WineHQ,ie.,to add the WineHQ signing key:
wget -qO- https://dl.winehq.org/wine-builds/Release.key | sudo apt-key add -

step 6 : Add the relevant repository from the WineHQ:
sudo apt-add-repository 'deb http://dl.winehq.org/wine-builds/ubuntu/ artful main'

step 7:Here you have two options about which release of Wine you want to install;
       the stable version or the development versions.
       WineHQ Stable:
       sudo apt-get install --install-recommends winehq-stable
       WineHQ Development:
       sudo apt-get install --install-recommends winehq-devel

step 8:In order to verify installation and checking which version is installed on your system,
       run the following command:
       wine --version

Program on CPU SCHEDULING - ROUND ROBIN ( NON PREEMPTIVE)

/* Program to implement ROUND ROBIN CPU SCHEDULING */
#include<stdio.h>
void main()
{
  int st[10],bt[10],wt[10],tat[10],n,tq;
  int i,count=0,swt=0,stat=0,temp,sq=0;
  float awt=0.0,atat=0.0;

  printf("Enter number of processes:");
  scanf("%d",&n);
  printf("Enter burst time for sequences:");
  for(i=0;i<n;i++)
   {
     scanf("%d",&bt[i]);
     st[i]=bt[i];
   }
   printf("\nEnter time quantum:");
   scanf("%d",&tq);
   while(1)
   {
     for(i=0,count=0;i<n;i++)
     {
       temp=tq;
       if(st[i]==0)
       {
     count++;
     continue;
       }
       if(st[i]>tq)
    st[i]=st[i]-tq;
       else
    if(st[i]>=0)
    {
      temp=st[i];
      st[i]=0;
    }
    sq=sq+temp;
    tat[i]=sq;
     }
     if(n==count)
     break;
   }
   for(i=0;i<n;i++)
   {
    wt[i]=tat[i]-bt[i];
    swt=swt+wt[i];
    stat=stat+tat[i];
   }
   awt=(float)swt/n;
   atat=(float)stat/n;
   printf("\n\tPno\tBT\tTAT\tWT\n");
   for(i=0;i<n;i++)
    printf("\n\t%d\t%d\t%d\t%d",i+1,bt[i],tat[i],wt[i]);
    printf("\n Avg wait time is %f \n Avg turn around time is %f\n",awt,atat);

}

























 

Program on CPU SCHEDULING - PRIORITY ( NON PREEMPTIVE)

/* Program to implement PRIORITY CPU SCHEDULING */
#include<stdio.h>

void main()
{
    int bt[10],p[10],priority[10],st[10],ct[10],tat[10],wt[10],n,i,j,temp;
    float sumtat=0,sumwt=0,avwt,avtat;
    printf("\nPriority Scheduling");
    printf("\nEnter Number of Processes:");
    scanf("%d",&n);
    printf("\nEnter %d Processes Details\n\n",n);
    for(i=0;i<n;i++)
    {
        printf("\nEnter Process %d ID:",i+1);
        scanf("%d",&p[i]);
        printf("\nEnter Process %d Burst Time:",i+1);
        scanf("%d",&bt[i]);
        printf("\nEnter Process %d Priority:",i+1);
        scanf("%d",&priority[i]);
    }

    for(i=0;i<n;i++)
    {
        for(j=0;j<n-1;j++)
        {
            if(priority[j]>priority[j+1])
            {
                //Swapping Processes Based on Priority
                temp=priority[j];
                priority[j]=priority[j + 1];
                priority[j + 1]=temp;
                //Swapping Process ID Accordingly
                temp=p[j];
                p[j]=p[j + 1];
                p[j +1]=temp;
                //Swapping Burst Time
                temp=bt[j];
                bt[j]=bt[j + 1];
                bt[j + 1]=temp;
            }

        }
    }

st[0]=0;
wt[0]=0;
ct[0]=st[0]+bt[0];
for(i=0;i<n;i++)
    {
        st[i+1]=st[i]+bt[i];
        ct[i+1]=st[i+1]+bt[i+1];
    }
   

for(i=0;i<n;i++)
    {
        tat[i]=ct[i] - 0;
        sumtat=sumtat+tat[i];
    }



for(i=0;i<n;i++)
    {
        wt[i]=tat[i]-bt[i];
        sumwt=sumwt+wt[i];
    }


printf("\n\tPNO\tPr\tbt\tst\tct\ttat\twt\n");
    for(i=0;i<n;i++)
    {
        printf("\n\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",p[i],priority[i],bt[i],st[i],ct[i],tat[i],wt[i]);
    }

avtat=sumtat/n;
avwt=sumwt/n;
printf("\n average waiting time is %f\n",avwt);
printf("\n average tutn around time is %f\n",avtat);
}


output: