Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Job control in linux with C

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.

like image 322
Yasser Souri Avatar asked Dec 28 '22 18:12

Yasser Souri


1 Answers

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.

like image 92
Ben Voigt Avatar answered Jan 04 '23 23:01

Ben Voigt