What I know:
When a process is running I can press Ctrl+Z and suspend it. The with bg
and fg
commands I can either run it in "background" or "foreground" mode.
What I'm aksing:
Is there a way to suspend a process, send it to run in background or foreground in C?
Edit: I have the process id. I want to send that process to the background for example.
You can suspend it with kill(pid, SIGSTOP)
, but making it foreground or background is a function of the shell that ran it, since what it actually affects is whether the shell displays a prompt (and accepts a new command) immediately or waits until the job exits. Unless the shell provides an RPC interface (like DBus), there's no clean way to change the waiting/not waiting flag.