tags:

views:

158

answers:

3

I am writing my own shell as part of course assignment. So I need to support background jobs. I am maintaining data strutures for job id and background jobs. But I need to tell kernel also that this is background process so that there is only one terminal foreground process. Till now I am handling background jobs at my program level.

What is the function call to register a background process?

+1  A: 

On Linux look at the daemon function:

 int daemon(int nochdir, int noclose);

If the daemon function doesn't exist on the system you're using you need to use setsid and fork instead.

atomice
I dont want a daemon process, but I just want to run a process in background. So I need a way to inform kernel.
avd
+1  A: 

Sorry, misread your question. You need to use thetcsetpgrpfunction.

Read this section in the GNU C Library Manual for details:

http://www.gnu.org/s/libc/manual/html_node/Job-Control.html

atomice
+2  A: 

If you want a process to not be part of the terminal's controlling group, the simplest method is to simply give it a different group.

switch (fork()) {
    case 0:
        setpgid(getpid(), getpid());
        execvp(...);
ephemient