UNIX System call to register a background process

Tag: unix Author: a929285902 Date: 2009-09-16

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 also tell the kernel that this is a background process, so that there is only one terminal foreground process. Until now I am handling background jobs at my program level.

What is the function call to register a background process?

I was reading this page the other day: win.tue.nl/~aeb/linux/lk/lk-10.html i like its way of teaching it
Duplicate of
@Jonathan, that's quite different. This guy wants to do job control, while that other question wants to start daemons. The daemons are disconnected from terminals, and don't interact with the user at all.
@litb: I think not. aditya's wording is awkward, but simplistic job control does seem to be what is desired, not daemonization.

Best Answer

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());

Other Answer1

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

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


Other Answer2

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.


I dont want a daemon process, but I just want to run a process in background. So I need a way to inform kernel.