I need some help regarding job control in linux.
I run my program out of a terminal, like this
$ ./test.elf &
My program/process is then being run as the background process.
After a while (let say 5 seconds), I type fg
to put my process in the foreground.
After a while (let say 5 seconds), I want my program to go back to the background process and put the bash program as the foreground process, so that I can continue using the terminal.
Here is what I do:
- When startng my pprogram, I get the group process id of the foreground process (the bash program) using
tcgetpgrp
function. - I then wait until my process is the foreground process. I use the
tcgetpgrp(STDIN__FILENO)
. - I then wait ~5 seconds
- Using
tcsetpgrp
I put the process which I got in point 1 above, in the foreground.
Problem is, I can see that my process is put in the background and the bash program in the foreground, but I cann't enter command in the terminal. The bash doesn't "return", it is still waiting or sleeping.
I know I can press Ctrl-z and then bg
but I don't want to use that because after Ctrl-z is pressed my process is stopped and that isn't good because I am running a "real-time" control application. So I want to switch back to the terminal "instantly" without stopping or pausing my program.
Sorry if my description of my problem seems confusing.
Any comments?