Thread: Signal handling

  1. #1
    Registered User
    Join Date
    Feb 2013
    Location
    Buea Cameroon
    Posts
    64

    Signal handling

    Please I am trying to create a program that would execute a foreground process.

    I have this code for the foreground process
    Code:
    #include <stdio.h>
    #include <signal.h>
    
    
    int main()
    {
       int temp;
       
    
    
       printf("We are in the current program\n");
       scanf("%d", &temp);
    
    
       printf("Leaving new program");
       
       return 0;
       
    }
    And this is my main program
    Code:
    #include <unistd.h>
    #include <signal.h>
    #include <stdio.h>
    
    
    int main()
    {
       signal(SIGINT, SIG_IGN);
       
       execvp("./scanf", NULL);
    
    
       printf("How are you");
       
       return 0;
    }
    My main program stops executing after the process "./scanf" executes and there fore does not print the line "How are You"

    I want to main program to continue executing after "./scanf" finishes. Any idea on how to achieve that?

  2. #2
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    execvp replaces the current process with the new one, so your program "stops executing" as soon as you call execvp. You need to call fork() first to make a new process.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Location
    Buea Cameroon
    Posts
    64
    Thanks man!
    It seems I have to do more reading on execvlp
    Last edited by acho.arnold; 02-03-2014 at 05:17 AM.
    Programmer & Aspiring Software Engineer
    Join Us and Lets Make a Difference

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. signal handling and exception handling
    By lehe in forum C++ Programming
    Replies: 2
    Last Post: 06-15-2009, 10:01 PM
  2. Signal handling
    By Zarniwoop in forum C Programming
    Replies: 6
    Last Post: 09-13-2008, 06:04 PM
  3. signal handling
    By quagsire in forum Linux Programming
    Replies: 8
    Last Post: 07-18-2002, 03:31 AM
  4. Signal handling
    By quagsire in forum Linux Programming
    Replies: 1
    Last Post: 07-08-2002, 07:54 AM
  5. signal handling
    By trekker in forum C Programming
    Replies: 2
    Last Post: 07-05-2002, 02:52 AM