COMP 3000 Lab 3 2011: Difference between revisions

From Soma-notes
No edit summary
Line 10: Line 10:


# Compile run-program.c with the command ''gcc -g run-program.c -o run-program'' and use it to answer the following questions.
# Compile run-program.c with the command ''gcc -g run-program.c -o run-program'' and use it to answer the following questions.
## Is the line "Is this line printed?" when you execute '''./run-program /bin/ls'''?  Why?
## Is the line "Is this line printed?" when you execute '''./run-program /bin/ls -a /tmp'''?  Why?
## Change the program to use execve instead of execvp .  What is the new line?
## Change the program to use execve instead of execvp .  What is the new line?


==Part B (on your own)==
* catch segfault signal, sigchild?
* make very simple shell based on skeleton?
* run fork bomb, play with priorities to reduce impact, set quota
# Create run-program-reverse.c that is the same as run-program.c except that it interprets its arguments in reverse order.  Hence, ''./run-program-reverse /tmp -a /bin/ls'' will do the same as ''./run-program /bin/ls -a /tmp''.
==Program Listings==


  /* run-program.c */
  /* run-program.c */
Line 29: Line 40:
     return 0;
     return 0;
  }
  }
==Part B (on your own)==
* catch segfault signal, sigchild?
* make very simple shell based on skeleton?
* run fork bomb, play with priorities to reduce impact, set quota

Revision as of 11:19, 17 October 2011

Please answer using text files. Do not use doc, docx, pdf etc. Submit your solutions via WebCT by October 21st at 8 PM.

Part A (in Tutorial)

Notes:

  • execve example
  • fork, execve example
  • generate, receive user signal
  • change scheduling priorities program
  1. Compile run-program.c with the command gcc -g run-program.c -o run-program and use it to answer the following questions.
    1. Is the line "Is this line printed?" when you execute ./run-program /bin/ls -a /tmp? Why?
    2. Change the program to use execve instead of execvp . What is the new line?


Part B (on your own)

  • catch segfault signal, sigchild?
  • make very simple shell based on skeleton?
  • run fork bomb, play with priorities to reduce impact, set quota
  1. Create run-program-reverse.c that is the same as run-program.c except that it interprets its arguments in reverse order. Hence, ./run-program-reverse /tmp -a /bin/ls will do the same as ./run-program /bin/ls -a /tmp.


Program Listings

/* run-program.c */

#include <unistd.h>
#include <stdio.h>

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

   if( argc < 2 ) {
       printf( "Insufficient arguments.\n" );
       return -1;
   }
   execvp( argv[1], argv + 1 );
   printf( "Is this line printed?\n" );
   return 0;
}