We have been working very hard since 2009 to facilitate in your learning Read More. We can't keep up without your support. Donate Now.

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More

CS-604 Assignment No#1 Due Date: 12-05-2016 .................... from 1st to 7th lectures..

Assignment Objective:

  • To give you hand on experience of Ubuntu though VMware
  • To know about system calls like fork, wait, and exec
  • How to work on Ubuntu terminal
  • How to compile a program using gcc compiler and execute a program through terminal

Uploading instructions:

  • Your assignment must be in .doc format (Any other formats like scan images, PDF, bmp, etc will not be accepted).
  • Save your assignment with your ID (e.g. bc020200786.doc).
  • No assignment will be accepted through email.

Rules for Marking:

 

It should be clear that your assignment will not get any credit if:

  • The assignment is submitted after due date.
  • The submitted assignment does not open or file is corrupted.
  • Your assignment is copied from internet, handouts or from any other student

      (Strict disciplinary action will be taken in this case).

Question

 

Write a C program in any editor of Linux in which you have to create one child using fork system call. In child process, message will be displayed to take input for two tasks through Switch or If else statements.

 

  • One for execution of ping command for any website i.e ping yahoo.com using the execlp() system call.
  • Second to create any directory using mkdir command i.e mkdir VU

 

Parent process should wait until child finishes its execution through Wait() call and display a message “Well done Kid”.

Finally Both Parent and Child ID should be displayed.

 

You have to solve the assignment in the following way

 

  • Save the program in your student id directory which can be created anywhere i.e Desktop
  • Attach only two screen shots i.e one for ping and other for mkdir
  • Also copy the code in the text format in the same word file in which screen shot attached.

 

Sample Program output:

Screen Shot 1:

Screen Shot 2:


+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)


Views: 23260

Attachments:

Replies to This Discussion

mera ubuntu nh ho rha down load ?????

agr ksi ny Ubuntu ka koi bhe virsion download krna hy to is "http://www.cyberciti.biz/tips/download-ubuntu-linux-11-10-iso-cd-dvd-images-oneiric-ocelot.html" link sy download kr sakty haen...!!!!

Is code ko compile karen ap loag ....

#include <sys/types.h>

#include <sys/wait.h>

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>


int main()
{

int pid, status, choice;

pid = fork();

if(pid == -1)
{

printf("fork failed\n");

exit(1);
}

if(pid == 0) /* Child */

{
printf("Enter 1 for ping and 2 for mking dir ");

scanf("%d",&choice);

switch(choice)
{

case 1 :

if(execlp("/bin/ping", "ping", "-c 4", "www.google.com", NULL)< 0);
{

printf("exec failed\n");

exit(1);
}

case 2 :

if(execlp("/bin/mkdir" , "mkdir" , "vu", NULL)< 0);

{
printf("exec failed\n");

exit(1);
}

break;

default:

printf("wrong choice");
}
}

else /* Parent */
{

wait(&status);

printf("Well done kid!\n");

printf("Parent id is %d", getpid());

printf("\nchild id is %d", pid);


exit(0);
}
}

ye test code he ya assignment ka code he.

Alahmdulilah 

R u done the assignment

Yes

CS604 solution with complete guidline

Attachments:

ALHAMDU LILLAH....done !!

#include <sys/types.h>

#include <sys/wait.h>

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>



int main()

{
    
int pid, status, choice;
    
pid = fork();
    
if(pid == -1)
    

{
        
printf("fork failed\n");
        
exit(1);
    
}
    

if(pid == 0)   /* Child */
    
{
        
printf("Enter 1 for ping and 2 for mking dir\n ");
        
scanf("%d",&choice);
        switch(choice)
        

{
        
case 1 :
            
if(execlp("/bin/ping", "ping", "-c 4", "www.yahoo.com", NULL)< 0);
            
{
                
printf("exec failed\n");
                
exit(1);
            
}
        

case 2 :
            
if(execlp("/bin/mkdir" , "mkdir" , "vu", NULL)< 0);
            
{
                
printf("exec failed\n");
                
exit(1);
            
}
            
break;
        

default:
            
printf("wrong choice");
        
}
    
}
    

else   /* Parent */
    
{
        
wait(&status);
        
printf("Well Done kid!\n");
        
printf("Parent id is %d", getpid());
        
printf("\nchild id is %d", pid);

        
exit(0);
    
}

}

Cheating 

abrar bhai word ki file mai day do please screen shot kay sath code bc120201490 meri id hai please

RSS

Looking For Something? Search Here

HELP SUPPORT

This is a member-supported website. Your contribution is greatly appreciated!

© 2020   Created by +M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service

.