Saturday, 23 November 2013

NOS SAMPLE QUESTIONS



S7 CSE EXTERNAL LAB EXAMINATION NOTICE

NOTE: SUBJECT CODES ARE WRONG... CONSIDER ONLY SUBJECT NAME... COME ACCORDING TO SUBJECT NAME ONLY...
if images below are not clear,,, u can see the pdf here: 
Bring Hall Ticket and Fair Record on the day of examination



Friday, 22 November 2013

To send palindrome back to parent process

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int main(){
  int pid,a,n,p[2],p2[2],i,len,j,k,flag,n2=0;
  char buffr1[100][100],buffr2[100][100],buf[5];
  printf("Enter the limit:- ");
  scanf("%d",&n);
  a = pipe(p);
  if(a == -1)
  {
     fprintf(stderr, "Pipe Failed.\n");
     return EXIT_FAILURE;
  }
  a = pipe(p2);
  if(a == -1)
  {
     fprintf(stderr, "Pipe Failed.\n");
     return EXIT_FAILURE;
  }
   pid = fork();
   switch(pid)
   {
     case -1:perror("main: fork");
exit(1);
     case 0: read(p[0],buffr2,sizeof(buffr2));
      printf("In child process (ID: %d)\n", pid);
      for(i=0;i<n;i++)
{
        len=strlen(buffr2[i]);
        flag=0;
        for(j=0,k=len-1;j<len;j++,k--)
{
if(buffr2[i][j]!=buffr2[i][k])
{
flag=1;
break;
}
        }
        if(flag==0)
{
n2++;
strcpy(buffr1[n2],buffr2[i]);
        }
      }
      buffr1[0][0]=n2;
      write(p2[1],buffr1,sizeof(buffr1));
      exit(1);
      break;
     default: printf("In parent process (ID: %d)\n", pid);
      for(i=0;i<n;i++)
{
        printf("Enter the string %d:- ",i+1);
        scanf("%s",buffr1[i]);
      }
      write(p[1],buffr1,sizeof(buffr1));
      waitpid(pid,NULL,0);
      read(p2[0],buffr2,sizeof(buffr2));
      printf("In parent process (ID: %d)\n", pid);
      n=(int) buffr2[0][0];
      for(i=1;i<=n;i++)
        printf("Palindrome %d:- %s\n",i,buffr2[i]);
      break;
}
    close(p[0]);
    close(p[1]);
close(p2[0]);
close(p2[1]);
    return 0;
}


To send back prime numbers to parent process

#include <stdio.h>     //for fprintf printf scanf stderr
#include <stdlib.h>    //for exit
#include <unistd.h>    //for pipe fork read write close
#include <math.h>      //for sqrt
#include <sys/types.h> //for waitpid
#include <sys/wait.h>  //for waitpid

int main(){
   int pid,a,n,p[2],p1[2],i,j,buffr1[100],buffr2[100],flag,n2=0, check;
   a = pipe(p);
   if(a == -1)
    {
       fprintf(stderr, "Pipe Failed.\n");
       return EXIT_FAILURE;
    }
   a=pipe(p1);
   if(a == -1)
    {
       fprintf(stderr, "Pipe Failed.\n");
       return EXIT_FAILURE;
    }
    pid = fork();
   switch(pid)
   {
       case -1:perror("main: fork");
          exit(1);
       case 0: n=read(p[0],buffr2,sizeof(buffr2));
          printf("In child process (ID: %d)\n", pid);
          n=n/sizeof(int);
          for(i=0;i<n;i++)
{
    flag=0;
    if(buffr2[i]<=1)
      flag=1;
check = sqrt(buffr2[i]);
    for(j=2;j<=check;j++)
{
      if((buffr2[i]%j)==0)
      {
  flag=1;
  break;
      }
    }
    if(flag==0)
{
      buffr1[n2]=buffr2[i];
      n2++;
    }
          }
          write(p1[1],buffr1,n2*sizeof(int));
          exit(1);
          break;
       default: printf("In parent process (ID: %d)\n", pid);
          printf("Enter the limit:- ");
          scanf("%d",&n);
          for(i=0;i<n;i++)
{
    printf("Enter the element %d:- ",i+1);
    scanf("%d",&buffr1[i]);
          }
          write(p[1],buffr1,n*sizeof(int));
          waitpid(pid,NULL,0);
          printf("In parent process (ID: %d)\n", pid);
          n2=read(p1[0],buffr2,sizeof(buffr2));
          n2=n2/sizeof(int);
          for(i=0;i<n2;i++)
            printf("Prime Number %d:- %d\n",i+1,buffr2[i]);
          break;
    }
    close(p[0]);
    close(p[1]);
close(p1[0]);
close(p1[1]);
    return 0;
}

To send N strings from parent to child process

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
   int pid,a,n,p[2],i;
   char buffr1[100][100],buffr2[100][100];
   printf("Enter the limit:- ");
   scanf("%d",&n);
   a = pipe(p);
   if(a == -1)
   {
       fprintf(stderr, "Pipe Failed.\n");
       return EXIT_FAILURE;
    }
    pid = fork();
switch(pid)
{
       case -1:perror("main: fork");
exit(1);
       case 0: read(p[0],buffr2,sizeof(buffr2));
          printf("In child process (ID: %d)\n", pid);
          for(i=0;i<n;i++)
            printf("String %d:- %s\n",i+1,buffr2[i]);
          exit(1);
          break;
       default: printf("In parent process (ID: %d)\n", pid);
          for(i=0;i<n;i++)
{
            printf("Enter the string %d:- ",i+1);
//gets(buffr1[i]);
//scanf ("%[^\n]%*c", buffr1[i]);
            scanf("%s",buffr1[i]);
          }
          write(p[1],buffr1,sizeof(buffr1));
          waitpid(pid,NULL,0);
          break;
    }
    close(p[0]);
    close(p[1]);
    return 0;
}

To send N numbers from a parent process to child process and display them.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
    int pid,a,n,p[2],i,buffr1[100],buffr2[100];
    a = pipe(p);
    if(a == -1)
    {
       fprintf(stderr, "Pipe Failed.\n");
       return EXIT_FAILURE;
    }
    pid = fork();
    switch(pid)
{
case -1:perror("main: fork");
exit(1);
case 0: n=read(p[0],buffr2,sizeof(buffr2));
printf("In child process (ID: %d)\n", pid);
n=n/sizeof(int);
for(i=0;i<n;i++)
printf("Number %d:- %d\n",i+1,buffr2[i]);
exit(1);
break;
default: printf("In parent process (ID: %d)\n", pid);
printf("Enter the limit:- ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the element %d:- ",i+1);
scanf("%d",&buffr1[i]);
}
write(p[1],buffr1,n*sizeof(int));
waitpid(pid,NULL,0);
break;
}
close(p[0]);
    close(p[1]);
    return 0;
}

REVERSE FILE CONTENT

#include <stdio.h>
#include <stdlib.h>

int main()
{
   char ch, source_file[20], dest_file[20],temp[500];
int count = 0,i;
   FILE *source, *dest;

   printf("Enter name of file to read :  ");
   gets(source_file);

   source = fopen(source_file, "r");

   printf("Enter name of target file where you want to store reversed characters :  ");
   gets(dest_file);

   dest = fopen(dest_file, "w");
int j=0;
   while( ( ch = fgetc(source) ) != EOF )
{
count += 1;
temp[j] = ch;
j++;
}

i=count-1;
while(i>-1)
{
fputc(temp[i], dest);
i--;
}

   printf("File copied successfully.\n");

   fclose(source);
   fclose(dest);

   return 0;
}

DISPLAY FILE ATTRIBUTES

#include<sys/stat.h>
#include<pwd.h>
#include<time.h>
#include<stdio.h>
int main()
{
    int s;
    char source[30],flag='y';
    struct stat filestat;
    struct passwd *pwd;
    printf("\nEnter the file name:- ");
    gets(source);
    s=stat(source,&filestat);
    if(s!=-1)
    {
        printf("\nOwner id: %d",filestat.st_uid);
      if((pwd = getpwuid(filestat.st_uid)) != NULL)
  {
  printf("\tname: %s", pwd->pw_name);
}
    printf("\nFile Size: %ld bytes",filestat.st_size);
    printf("\nFile Permission (Octal Notation): %o", filestat.st_mode);
   
printf("\nFile Permissions (Symbolic Notation): \t");
printf( (S_ISDIR(filestat.st_mode))      ?    "d"  : "-" );
printf( (filestat.st_mode & S_IRUSR)  ?    "r"   : "-" );
printf( (filestat.st_mode & S_IWUSR) ?    "w" : "-" );
printf( (filestat.st_mode & S_IXUSR)  ?    "x"  : "-" );
printf( (filestat.st_mode & S_IRGRP)  ?    "r"   : "-" );
printf( (filestat.st_mode & S_IWGRP) ?    "w" : "-" );
printf( (filestat.st_mode & S_IXGRP)  ?    "x"  : "-" );
printf( (filestat.st_mode & S_IROTH)  ?    "r"  : "-" );
printf( (filestat.st_mode & S_IWOTH) ?    "w" : "-" );
printf( (filestat.st_mode & S_IXOTH)  ?   "x"  : "-" );

    printf("\nDate of creation: %s",ctime(&filestat.st_ctime));
    printf("Last Modified Date: %s",ctime(&filestat.st_mtime));
  printf("\n");
    }
    else
        printf("\nError!!!");
    return 0;
}

REPLICATING DOS COPY COMMAND

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{

if(argc!=3)
{
printf("Not enough arguments... :P ");
exit(0);
}
   char ch;
   FILE *source, *dest;

   source = fopen(argv[1], "r");

   dest = fopen(argv[2], "w");

   while( ( ch = fgetc(source) ) != EOF )
      fputc(ch, dest);

   printf("File copied successfully.\n");

   fclose(source);
   fclose(dest);

   return 0;
}


TO RUN THE PROGRAM:
gcc program_name.c -o cpy
./cpy source_file_name dest_file_name

------------------------------------------------------------------------------------------------------------

#include<stdio.h>
#include<stdlib.h>
int main()
{
char command[100],source[100],destination[100];
int ret;
printf("\nEnter the source file name ");
gets(source);
printf("\nEnter the destination file name ");
gets(destination);
sprintf(command,"cp %s %s",source,destination);
ret=system(command);
if(ret==0)
    printf("Successfully Copied from %s to %s\n",source,destination);
return 0;
}

TO RUN THE PROGRAM:
gcc program_name.c -o cpy
./cpy

Thursday, 21 November 2013

S7 CSE LAB SCHEDULE (EXTERNAL LAB EXAM)



Is there any difficulty in looking in picture, Download PDF here: LP LAB & NOS LAB

NOTE: Subject codes are incorrect... It won't be a problem for regular students... Supplementary students please re-check the schedule on 23rd evening. Thank-you.

Subject