previous | start | next

Managing the Terminal Foreground Process Group

Which process group is the terminal foreground process can be determined and/or set by these system calls:

       #include <unistd.h>

       pid_t tcgetpgrp(int fd);

       int tcsetpgrp(int fd, pid_t pgrp);

where

Example 1: A process makes itself the foreground process:

        tcsetpgrp(0, getpid());
     

Example 2: Make some other process with pid 1403 (in the same session) be the foreground process:

        tcsetpgrp(0, 1403);
     

Example 3: Get the group pid of the foreground process for the controlling terminal of the calling process:

        pid_t gid;

        gid = tcgetpgrp(0);

     

Each of these functions returns -1 if there is an error. Errors occur if there is no controlling terminal associated with the calling process or if the file descriptor (0 in the examples) is not a valid file descriptor for the calling process or if the process group (e.g.1403) is not in the same session as the calling process. (See the man pages for details.)



previous | start | next