In: Computer Science
how to send background process to foreground process using c code?
To send a process or to run a process in a system whther in foreground or in background there is a function named as tcsetpgrp which is used for both the purpose. It's just there parameters change according to the requirements. The command for running any process in foreground is -
tcsetpgrp (shell_terminal, j->pgid) ;
The code in c for sending a background process j to foreground is -
void
put_jobforeground (job *j, int conti)
{tcsetpgrp (shell_terminal, j->pgid); ##put the job in foreground.
wait_for_job (j); #wait for the job to report.
tcsetpgrp (shell_terminal, shell_pgid); #put the shell back in Foreground if sent to background.
tcgetattr (shell_terminal, &j->tmodes); #restore the nodes.
tcsetattr (shell_terminal, TCSADRAIN, &shell_tmodes);
}
By this code you can easily run any process in the foreground or can send the process to foreground if it's in the backgroud.