Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8858727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:53:38+00:00 2026-06-14T14:53:38+00:00

I’m implementing a Terminal for a Home Work. I almost finished, I just need

  • 0

I’m implementing a Terminal for a Home Work.
I almost finished, I just need to implement a bg ( Background ) and a fg ( Foreground ) commands.
my code looks like this:

void run(){

    string command[] = parseMyInput( getInput() );  
    int fork_result = fork();
    if( -1 == fork_result )
        //handle error
    else if( 0 == fork_result ){  // child

         setpgrp();  // I don't want the children to get the signals

         if( -1 == execvp( command[0], makeArgs(command) ) )
             //handle error
    }
    else {  // parent

        if( command[ length - 1 ] != "&" ){

            int status;
            waitpid( fork_result, &status, 0 );

            //continue after child is finished
           //( need to be here also after a SIGTSTP is raised by ctrl+z )
        }
    }

If it is a foreground process ( if there wasn’t a ‘&’ sign at the end ) then I need to be able to stop the foreground process ( the child ) with ctrl+z ( SIGTSTP ) and then to return the control to the father ( my terminal ) from the point it stopped ( waitpid ).

the problem is that after a ctrl+z is pressed, ( and after the parent get the control in the signal handle method and stop the child using kill( child_pid, SIGTSTP ) ) the parent don’t continue from where it stopped ( the waitpid ). I don’t know where it continue after the signal handling method is finished.

If I call run() at the signal handling method it will work, but I don’t want the recursion. I’m guessing I’ll get a StackOverFlow very soon…

here is the code of the Signal Handling Method:

void sigtstp_handel( int signal ){  

    if( is_foreground_process_alive() )
        kill( foreground_process_pid, SIGTSTP );

    // run();
}  

EDIT: I don’t know if it will matter, but I’m using a Linux Ubuntu 12.10. nevertheless, for the Home Work, I’ll need it to work on other systems.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:53:39+00:00Added an answer on June 14, 2026 at 2:53 pm

    Reading the official POSIX reference for waitpid:

    WUNTRACED

    The status of any child processes specified by pid that are stopped,
    and whose status has not yet been reported since they stopped, shall
    also be reported to the requesting process.
    

    So if you add the WUNTRACED flag the waitpid call should return when the process it waits for is stopped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an autohotkey script which looks up a word in a bilingual dictionary
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.