program coding

Upload: beth-morris

Post on 04-Apr-2018

229 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Program Coding

    1/22

    411711205000

    Program coding://implementation of fork(),exe(),wait system call#includeint main()

    {int pid;printf("\nwelcome");pid=fork();printf("\n process id is:%d",pid);if(pid

  • 7/29/2019 Program Coding

    2/22

    411711205000

    Output:[prince20@localhost ~]$ cc sc.c[prince20@localhost ~]$ ./a.out

    welcomeprocess id is:0welcomeprocess id is:5398

    \ client.c file2 jp packet.c rpc.x simp_svc.caa.c creat.c flwr large.c packets.c rpc_xdr.c simp.xACE cse getpid.c larger.c pp sc.c simp_xdr.ca.out datec.c great.c ls pp.c ser3.c sjfasds dates.c grep.c make.c priority.c server sjf.casia dnsc.c gsc.c maki.c process.c server1.c stat.cchatc.c dnss.c iosc.c making.c rpc2.x server2.c sumchats.c dp iosc.h mksc.c rpcc.c server3.c systemcl3.c echoc.c iosc.h.gch ocsc.c rpc_clnt.c short.c udp.cclient echos.c it open rpc.h simpc.c udpc.cclient1.c fcfs.c j open.c rpcint.c simp_clnt.c udps.cclient2.c file jana oper?n rpcs.c simp.hclient3.c file1 jaya os rpc_svc.c simps.cparent processrecsived terminal staus of parent process

    end[prince20@localhost ~]$

  • 7/29/2019 Program Coding

    3/22

    411711205000

    Program coding:#includeint main(){

    int pid;pid=getpid();printf("\n process id is %d",pid);}

  • 7/29/2019 Program Coding

    4/22

    411711205000

    Output:"gsc.c" 7L, 91C written[prince20@localhost ~]$ cc gsc.c[prince20@localhost ~]$ ./a.out

    process id is 5501[prince20@localhost ~]$

  • 7/29/2019 Program Coding

    5/22

    411711205000

    program coding:#include#includemain()

    {DIR *dp;struct dirent *d;dp=opendir("dp");if(dp==NULL)printf("\n directory not available");else{printf("\n content of the directory");while((d=readdir(dp))!=NULL)printf("\n %s \n",d->d_name);}closedir(dp);}

  • 7/29/2019 Program Coding

    6/22

    411711205000

    Output:[prince01@localhost ~]$ cc op.c[prince01@localhost ~]$ ./a.out

    contents of the directory..

    flowers

    .[prince01@localhost ~]$

  • 7/29/2019 Program Coding

    7/22

    411711205000

    Program coding:#include#includemain()

    {char buf[100];getcwd(buf,100);printf("\n current working directory %s",buf);mkdir("cse");chdir("cse");getcwd(buf,100);printf("\n directory changed");printf("\n current working directory is %s",buf);}

  • 7/29/2019 Program Coding

    8/22

    411711205000

    Output:

    [prince01@localhost ~]$ cc mk.c[prince01@localhost ~]$ ./a.out

    current working directory /home/prince01directory changedcurrent working directory is /home/prince01/cse[prince01@localhost ~]$

  • 7/29/2019 Program Coding

    9/22

    411711205000

    program coding:#include#include

    #include#includeint main(){int fd;char buf1[100],fname[30];char buf2[]="operating system";printf("\n enter the file name");scanf("%s",fname);if((fd=creat(fname,S_IRWXU))

  • 7/29/2019 Program Coding

    10/22

    411711205000

    Output:"io.c" 29L, 478C writtenprince13@localhost ~]$ cc io.c

    [prince13@localhost ~]$ ./a.out

    enter the file namesystem

    contents written successfullythe contents is operating system[prince13@localhost ~]$

  • 7/29/2019 Program Coding

    11/22

    411711205000

    Program coding:#include#include

    #includemain(){struct stat*s;char *f;printf("\n enter the file name");scanf("%s",&f);stat(f,s);printf("\nlast access time:%d",s->st_atime);printf("\n last modified time:%d",s->st_mtime);printf("\n no of links:%d",s->st_nlink);}

  • 7/29/2019 Program Coding

    12/22

    411711205000

    Output:"stat.c" 14L, 291C written[prince20@localhost ~]$ cc stat.c

    [prince20@localhost ~]$ ./a.out

    enter the file nameabcd

    last access time:-331011108last modified time:1157826629no of links:-2062790005[prince20@localhost ~]$

  • 7/29/2019 Program Coding

    13/22

    411711205000

    Program coding:#include#include

    #includeint main( int argc){int ch,n,c;int i;do{printf("\n 1.list of files \n2.list pattern of file");printf("\n do u want to continue?(yes=1,no=0)");scanf("%d",&c);printf("\n enter your choice");scanf("%d",&n);DIR*dp;struct dirent*dirp;switch(n){case 1:if(argc==1)

    {dp=opendir("./");

    while((dirp=readdir(dp))!=NULL)printf(" %s\t",dirp->d_name);}elseprintf("\n error having too many parameters");break;

    case 2:system("grep asia jana" );break;default:

    exit(0);}}while(c==1);}

  • 7/29/2019 Program Coding

    14/22

    411711205000

    Output:

    "grep.c" 35L, 625C written[prince01@localhost ~]$ cc grep.c

    grep.c: In function main:grep.c:31: warning: incompatible implicit declaration of built-in function exit[prince01@localhost ~]$ ./a.out

    1.list of files2.list pattern of filedo u want to continue?(yes=1,no=0)1

    enter your choice1gg.c rint_svc.c sys.c first.c .sjf.c.swp .ab11.c.swo.dnsc.c.swp dtc.c system.c it jana job.c dnsc.h .pac.c.swo pri.c sa.c pac.c server r.c .bash_logout gre.c grep.csimp.h rpcmc.c .usc.c.swp mk.c .lesshst rint_clnt.c

    1.list of files2.list pattern of filedo u want to continue?(yes=1,no=0)1

    enter your choice2asia is continenti like asia

    1.list of files2.list pattern of filedo u want to continue?(yes=1,no=0)1

    enter your choice3

    [prince01@localhost ~]$

  • 7/29/2019 Program Coding

    15/22

    411711205000

    Program coding:#includemain(){

    int n,a[10],b[10],t[10],w[10],g[10],i,m;float att=0,awt=0;for(i=0;i

  • 7/29/2019 Program Coding

    16/22

    411711205000

    printf("\n");printf("\n %d",w[i]);printf("\t");for(i=1;i

  • 7/29/2019 Program Coding

    17/22

    411711205000

    Output:"first.c" 51L, 937C written[prince01@localhost ~]$ cc first.c[prince01@localhost ~]$ ./a.out

    enter the number of process:3

    enter the burst time:1

    enter the arrival time:1

    enter the burst time:2

    enter the arrival time:2

    enter the burst time:3

    enter the arrival time:3

    process waiting time turn around time

    1 -1 02 -1 1

    3 0 3average waiting time:-0.666667msaverage turn around time:1.333333msgantt chart......

    2 3 0

    0 0

    .......

    [prince01@localhost ~]$

  • 7/29/2019 Program Coding

    18/22

    411711205000

    Program coding:#include#includestatic int w;

    int twt,ttt,a[20],wt[20],n,bu[20];float att,awt;char pname[20][20];void getdata();void SJF();void getdata(){int i;printf("/n enter the number of process:");scanf("%d",&n);for(i=1;i

  • 7/29/2019 Program Coding

    19/22

    411711205000

    {temp=b[j-1];temp1=a[j-1];b[j-1]=b[j];

    a[j-1]=a[j];b[j]=temp;a[j]=temp1;strcpy(c[j-1],pname[j-1]);strcpy(pname[j-1],pname[j]);strcpy(pname[j],c[j-1]);}}}wt[1]=0;w=w+b[1];t=w;s[1]='F';while(w

  • 7/29/2019 Program Coding

    20/22

    411711205000

    printf("\n...........\n");for(i=1;i

  • 7/29/2019 Program Coding

    21/22

    411711205000

    Output:"job.c" 103L, 1534C written[prince08@localhost ~]$ cc job.c[prince08@localhost ~]$ ./a.out

    /n enter the number of process:4

    enter the process name:aenter the burst time for process a=8enter the arrival name for process:a=0

    enter the process name:benter the burst time for process b=4enter the arrival name for process:b=3

    enter the process name:center the burst time for process c=6enter the arrival name for process:c=4

    enter the process name:denter the burst time for process d=5enter the arrival name for process:d=2

    shortest job scheduling:

    average waiting time=12.750000msaverage turn around time 7.000000ms

    gannt chart...........| a | b | d | c

    ...........

    0 8 12 17............

    [prince08@localhost ~]$

  • 7/29/2019 Program Coding

    22/22

    411711205000