I use the terminal for work at home.
I'm almost done, I just need to implement the bg (Background) and fg (Foreground) commands.
my code is as follows:
void run(){ string command[] = parseMyInput( getInput() ); int fork_result = fork(); if( -1 == fork_result )
If this is a foreground process (if there was no "&" at the end), I will need to stop the foreground process (child) using ctrl + z (SIGTSTP), and then return the control to my father (my terminal) from the moment it stops (waitpid).
the problem is that after pressing ctrl + z (and after the parent receives the control in the signal descriptor method and stops it with kill (child_pid, SIGTSTP)), the parent will not continue from where it left off (waitpid). I do not know where it continues after signal processing is complete.
If I call run () in the signal processing method, it will work, but I do not want recursion. I guess I will get StackOverFlow soon ...
here is the code of the signal processing method:
void sigtstp_handel( int signal ){ if( is_foreground_process_alive() ) kill( foreground_process_pid, SIGTSTP );
EDIT: I don't know if this will make a difference, but I'm using Linux Ubuntu 12.10. however, for Homework I will need this to work with other systems.
Thanks!
source share