blob: a3f4b6cda80a7d80591ff58a61905be575533533 [file] [log] [blame]
<html lang="en">
<head>
<title>Terminal Access Functions - The GNU C Library</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="The GNU C Library">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Functions-for-Job-Control.html#Functions-for-Job-Control" title="Functions for Job Control">
<link rel="prev" href="Process-Group-Functions.html#Process-Group-Functions" title="Process Group Functions">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This file documents the GNU C library.
This is Edition 0.12, last updated 2007-10-27,
of `The GNU C Library Reference Manual', for version
2.8 (Sourcery G++ Lite 2011.03-41).
Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002,
2003, 2007, 2008, 2010 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software Needs Free Documentation''
and ``GNU Lesser General Public License'', the Front-Cover texts being
``A GNU Manual'', and with the Back-Cover Texts as in (a) below. A
copy of the license is included in the section entitled "GNU Free
Documentation License".
(a) The FSF's Back-Cover Text is: ``You have the freedom to
copy and modify this GNU manual. Buying copies from the FSF
supports it in developing GNU and promoting software freedom.''-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
<link rel="stylesheet" type="text/css" href="../cs.css">
</head>
<body>
<div class="node">
<a name="Terminal-Access-Functions"></a>
<p>
Previous:&nbsp;<a rel="previous" accesskey="p" href="Process-Group-Functions.html#Process-Group-Functions">Process Group Functions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Functions-for-Job-Control.html#Functions-for-Job-Control">Functions for Job Control</a>
<hr>
</div>
<h4 class="subsection">27.7.3 Functions for Controlling Terminal Access</h4>
<p>These are the functions for reading or setting the foreground
process group of a terminal. You should include the header files
<samp><span class="file">sys/types.h</span></samp> and <samp><span class="file">unistd.h</span></samp> in your application to use
these functions.
<a name="index-unistd_002eh-3244"></a><a name="index-sys_002ftypes_002eh-3245"></a>
Although these functions take a file descriptor argument to specify
the terminal device, the foreground job is associated with the terminal
file itself and not a particular open file descriptor.
<!-- unistd.h -->
<!-- POSIX.1 -->
<div class="defun">
&mdash; Function: pid_t <b>tcgetpgrp</b> (<var>int filedes</var>)<var><a name="index-tcgetpgrp-3246"></a></var><br>
<blockquote><p>This function returns the process group ID of the foreground process
group associated with the terminal open on descriptor <var>filedes</var>.
<p>If there is no foreground process group, the return value is a number
greater than <code>1</code> that does not match the process group ID of any
existing process group. This can happen if all of the processes in the
job that was formerly the foreground job have terminated, and no other
job has yet been moved into the foreground.
<p>In case of an error, a value of <code>-1</code> is returned. The
following <code>errno</code> error conditions are defined for this function:
<dl>
<dt><code>EBADF</code><dd>The <var>filedes</var> argument is not a valid file descriptor.
<br><dt><code>ENOSYS</code><dd>The system doesn't support job control.
<br><dt><code>ENOTTY</code><dd>The terminal file associated with the <var>filedes</var> argument isn't the
controlling terminal of the calling process.
</dl>
</p></blockquote></div>
<!-- unistd.h -->
<!-- POSIX.1 -->
<div class="defun">
&mdash; Function: int <b>tcsetpgrp</b> (<var>int filedes, pid_t pgid</var>)<var><a name="index-tcsetpgrp-3247"></a></var><br>
<blockquote><p>This function is used to set a terminal's foreground process group ID.
The argument <var>filedes</var> is a descriptor which specifies the terminal;
<var>pgid</var> specifies the process group. The calling process must be a
member of the same session as <var>pgid</var> and must have the same
controlling terminal.
<p>For terminal access purposes, this function is treated as output. If it
is called from a background process on its controlling terminal,
normally all processes in the process group are sent a <code>SIGTTOU</code>
signal. The exception is if the calling process itself is ignoring or
blocking <code>SIGTTOU</code> signals, in which case the operation is
performed and no signal is sent.
<p>If successful, <code>tcsetpgrp</code> returns <code>0</code>. A return value of
<code>-1</code> indicates an error. The following <code>errno</code> error
conditions are defined for this function:
<dl>
<dt><code>EBADF</code><dd>The <var>filedes</var> argument is not a valid file descriptor.
<br><dt><code>EINVAL</code><dd>The <var>pgid</var> argument is not valid.
<br><dt><code>ENOSYS</code><dd>The system doesn't support job control.
<br><dt><code>ENOTTY</code><dd>The <var>filedes</var> isn't the controlling terminal of the calling process.
<br><dt><code>EPERM</code><dd>The <var>pgid</var> isn't a process group in the same session as the calling
process.
</dl>
</p></blockquote></div>
<!-- termios.h -->
<!-- Unix98 -->
<div class="defun">
&mdash; Function: pid_t <b>tcgetsid</b> (<var>int fildes</var>)<var><a name="index-tcgetsid-3248"></a></var><br>
<blockquote><p>This function is used to obtain the process group ID of the session
for which the terminal specified by <var>fildes</var> is the controlling terminal.
If the call is successful the group ID is returned. Otherwise the
return value is <code>(pid_t) -1</code> and the global variable <var>errno</var>
is set to the following value:
<dl>
<dt><code>EBADF</code><dd>The <var>filedes</var> argument is not a valid file descriptor.
<br><dt><code>ENOTTY</code><dd>The calling process does not have a controlling terminal, or the file
is not the controlling terminal.
</dl>
</p></blockquote></div>
</body></html>