This file is indexed.

/usr/share/gap/doc/ref/chap11.html is in gap-doc 4r8p6-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>GAP (ref) - Chapter 11: Processes</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content="GAPDoc2HTML" />
<link rel="stylesheet" type="text/css" href="manual.css" />
<script src="manual.js" type="text/javascript"></script>
<script type="text/javascript">overwriteStyle();</script>
</head>
<body class="chap11"  onload="jscontent()">


<div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chap8.html">8</a>  <a href="chap9.html">9</a>  <a href="chap10.html">10</a>  <a href="chap11.html">11</a>  <a href="chap12.html">12</a>  <a href="chap13.html">13</a>  <a href="chap14.html">14</a>  <a href="chap15.html">15</a>  <a href="chap16.html">16</a>  <a href="chap17.html">17</a>  <a href="chap18.html">18</a>  <a href="chap19.html">19</a>  <a href="chap20.html">20</a>  <a href="chap21.html">21</a>  <a href="chap22.html">22</a>  <a href="chap23.html">23</a>  <a href="chap24.html">24</a>  <a href="chap25.html">25</a>  <a href="chap26.html">26</a>  <a href="chap27.html">27</a>  <a href="chap28.html">28</a>  <a href="chap29.html">29</a>  <a href="chap30.html">30</a>  <a href="chap31.html">31</a>  <a href="chap32.html">32</a>  <a href="chap33.html">33</a>  <a href="chap34.html">34</a>  <a href="chap35.html">35</a>  <a href="chap36.html">36</a>  <a href="chap37.html">37</a>  <a href="chap38.html">38</a>  <a href="chap39.html">39</a>  <a href="chap40.html">40</a>  <a href="chap41.html">41</a>  <a href="chap42.html">42</a>  <a href="chap43.html">43</a>  <a href="chap44.html">44</a>  <a href="chap45.html">45</a>  <a href="chap46.html">46</a>  <a href="chap47.html">47</a>  <a href="chap48.html">48</a>  <a href="chap49.html">49</a>  <a href="chap50.html">50</a>  <a href="chap51.html">51</a>  <a href="chap52.html">52</a>  <a href="chap53.html">53</a>  <a href="chap54.html">54</a>  <a href="chap55.html">55</a>  <a href="chap56.html">56</a>  <a href="chap57.html">57</a>  <a href="chap58.html">58</a>  <a href="chap59.html">59</a>  <a href="chap60.html">60</a>  <a href="chap61.html">61</a>  <a href="chap62.html">62</a>  <a href="chap63.html">63</a>  <a href="chap64.html">64</a>  <a href="chap65.html">65</a>  <a href="chap66.html">66</a>  <a href="chap67.html">67</a>  <a href="chap68.html">68</a>  <a href="chap69.html">69</a>  <a href="chap70.html">70</a>  <a href="chap71.html">71</a>  <a href="chap72.html">72</a>  <a href="chap73.html">73</a>  <a href="chap74.html">74</a>  <a href="chap75.html">75</a>  <a href="chap76.html">76</a>  <a href="chap77.html">77</a>  <a href="chap78.html">78</a>  <a href="chap79.html">79</a>  <a href="chap80.html">80</a>  <a href="chap81.html">81</a>  <a href="chap82.html">82</a>  <a href="chap83.html">83</a>  <a href="chap84.html">84</a>  <a href="chap85.html">85</a>  <a href="chap86.html">86</a>  <a href="chap87.html">87</a>  <a href="chapBib.html">Bib</a>  <a href="chapInd.html">Ind</a>  </div>

<div class="chlinkprevnexttop">&nbsp;<a href="chap0.html">[Top of Book]</a>&nbsp;  <a href="chap0.html#contents">[Contents]</a>&nbsp;  &nbsp;<a href="chap10.html">[Previous Chapter]</a>&nbsp;  &nbsp;<a href="chap12.html">[Next Chapter]</a>&nbsp;  </div>

<p id="mathjaxlink" class="pcenter"><a href="chap11_mj.html">[MathJax on]</a></p>
<p><a id="X7882133B7BDD51BC" name="X7882133B7BDD51BC"></a></p>
<div class="ChapSects"><a href="chap11.html#X7882133B7BDD51BC">11 <span class="Heading">Processes</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap11.html#X8390266186E61CCE">11.1 <span class="Heading">Process and Exec</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap11.html#X7B09033178D1107A">11.1-1 Process</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap11.html#X81402C91833986FC">11.1-2 Exec</a></span>
</div></div>
</div>

<h3>11 <span class="Heading">Processes</span></h3>

<p><strong class="pkg">GAP</strong> can call other programs, such programs are called <em>processes</em>. There are two kinds of processes: first there are processes that are started, run and return a result, while <strong class="pkg">GAP</strong> is suspended until the process terminates. Then there are processes that will run in parallel to <strong class="pkg">GAP</strong> as subprocesses and <strong class="pkg">GAP</strong> can communicate and control the processes using streams (see <code class="func">InputOutputLocalProcess</code> (<a href="chap10.html#X820799A3824684AC"><span class="RefLink">10.8-2</span></a>)).</p>

<p><a id="X8390266186E61CCE" name="X8390266186E61CCE"></a></p>

<h4>11.1 <span class="Heading">Process and Exec</span></h4>

<p><a id="X7B09033178D1107A" name="X7B09033178D1107A"></a></p>

<h5>11.1-1 Process</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Process</code>( <var class="Arg">dir</var>, <var class="Arg">prg</var>, <var class="Arg">stream-in</var>, <var class="Arg">stream-out</var>, <var class="Arg">options</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p><code class="func">Process</code> runs a new process and returns when the process terminates. It returns the return value of the process if the operating system supports such a concept.</p>

<p>The first argument <var class="Arg">dir</var> is a directory object (see <a href="chap9.html#X85030B35865A1080"><span class="RefLink">9.3</span></a>) which will be the current directory (in the usual UNIX or MSDOS sense) when the program is run. This will only matter if the program accesses files (including running other programs) via relative path names. In particular, it has nothing to do with finding the binary to run.</p>

<p>In general the directory will either be the current directory, which is returned by <code class="func">DirectoryCurrent</code> (<a href="chap9.html#X7BAD8036849E8430"><span class="RefLink">9.3-4</span></a>) –this was the behaviour of <strong class="pkg">GAP</strong> 3– or a temporary directory returned by <code class="func">DirectoryTemporary</code> (<a href="chap9.html#X8222B1A886E6195E"><span class="RefLink">9.3-3</span></a>). If one expects that the process creates temporary or log files the latter should be used because <strong class="pkg">GAP</strong> will attempt to remove these directories together with all the files in them when quitting.</p>

<p>If a program of a <strong class="pkg">GAP</strong> package which does not only consist of <strong class="pkg">GAP</strong> code needs to be launched in a directory relative to certain data libraries, then the first entry of <code class="func">DirectoriesPackageLibrary</code> (<a href="chap76.html#X807D835C7B032D4E"><span class="RefLink">76.3-5</span></a>) should be used. The argument of <code class="func">DirectoriesPackageLibrary</code> (<a href="chap76.html#X807D835C7B032D4E"><span class="RefLink">76.3-5</span></a>) should be the path to the data library relative to the package directory.</p>

<p>If a program calls other programs and needs to be launched in a directory containing the executables for such a <strong class="pkg">GAP</strong> package then the first entry of <code class="func">DirectoriesPackagePrograms</code> (<a href="chap76.html#X794508E5811D3BC9"><span class="RefLink">76.3-6</span></a>) should be used.</p>

<p>The latter two alternatives should only be used if absolutely necessary because otherwise one risks accumulating log or core files in the package directory.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">path := DirectoriesSystemPrograms();;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ls := Filename( path, "ls" );;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">stdin := InputTextUser();;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">stdout := OutputTextUser();;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Process( path[1], ls, stdin, stdout, ["-c"] );;</span>
awk    ls     mkdir
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput"># current directory, here the root directory</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Process( DirectoryCurrent(), ls, stdin, stdout, ["-c"] );;</span>
bin    lib    trans  tst    CVS    grp    prim   thr    two
src    dev    etc    tbl    doc    pkg    small  tom
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput"># create a temporary directory</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">tmpdir := DirectoryTemporary();;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Process( tmpdir, ls, stdin, stdout, ["-c"] );;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">PrintTo( Filename( tmpdir, "emil" ) );</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Process( tmpdir, ls, stdin, stdout, ["-c"] );;</span>
emil
</pre></div>

<p><var class="Arg">prg</var> is the filename of the program to launch, for portability it should be the result of <code class="func">Filename</code> (<a href="chap9.html#X7E352E1F87060602"><span class="RefLink">9.4-1</span></a>) and should pass <code class="func">IsExecutableFile</code> (<a href="chap9.html#X83A1AAD58435FC4C"><span class="RefLink">9.6-4</span></a>). Note that <code class="func">Process</code> does <em>no</em> searching through a list of directories, this is done by <code class="func">Filename</code> (<a href="chap9.html#X7E352E1F87060602"><span class="RefLink">9.4-1</span></a>).</p>

<p><var class="Arg">stream-in</var> is the input stream that delivers the characters to the process. For portability it should either be <code class="func">InputTextNone</code> (<a href="chap10.html#X7C732324806716C6"><span class="RefLink">10.9-1</span></a>) (if the process reads no characters), <code class="func">InputTextUser</code> (<a href="chap10.html#X83531E4C7C53544F"><span class="RefLink">10.6-1</span></a>), the result of a call to <code class="func">InputTextFile</code> (<a href="chap10.html#X8343D04981128784"><span class="RefLink">10.5-1</span></a>) from which no characters have been read, or the result of a call to <code class="func">InputTextString</code> (<a href="chap10.html#X7ABABCDF7ED81F7F"><span class="RefLink">10.7-1</span></a>).</p>

<p><code class="func">Process</code> is free to consume <em>all</em> the input even if the program itself does not require any input at all.</p>

<p><var class="Arg">stream-out</var> is the output stream which receives the characters from the process. For portability it should either be <code class="func">OutputTextNone</code> (<a href="chap10.html#X7CC5C1FC81715E38"><span class="RefLink">10.9-2</span></a>) (if the process writes no characters), <code class="func">OutputTextUser</code> (<a href="chap10.html#X83E5FC9487766297"><span class="RefLink">10.6-2</span></a>), the result of a call to <code class="func">OutputTextFile</code> (<a href="chap10.html#X83F53291822B7126"><span class="RefLink">10.5-2</span></a>) to which no characters have been written, or the result of a call to <code class="func">OutputTextString</code> (<a href="chap10.html#X7FEDA5167979B74D"><span class="RefLink">10.7-2</span></a>).</p>

<p><var class="Arg">options</var> is a list of strings which are passed to the process as command line argument. Note that no substitutions are performed on the strings, i.e., they are passed immediately to the process and are not processed by a command interpreter (shell). Further note that each string is passed as one argument, even if it contains <em>space</em> characters. Note that input/output redirection commands are <em>not</em> allowed as <var class="Arg">options</var>.</p>

<p>In order to find a system program use <code class="func">DirectoriesSystemPrograms</code> (<a href="chap9.html#X808E2C187DD984B4"><span class="RefLink">9.3-6</span></a>) together with <code class="func">Filename</code> (<a href="chap9.html#X7E352E1F87060602"><span class="RefLink">9.4-1</span></a>).</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">path := DirectoriesSystemPrograms();;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">date := Filename( path, "date" );</span>
"/bin/date"
</pre></div>

<p>The next example shows how to execute <code class="code">date</code> with no argument and no input, and collect the output into a string stream.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">str := "";; a := OutputTextString(str,true);;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Process( DirectoryCurrent(), date, InputTextNone(), a, [] );</span>
0
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">CloseStream(a);</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print(str);</span>
Fri Jul 11 09:04:23 MET DST 1997
</pre></div>

<p><a id="X81402C91833986FC" name="X81402C91833986FC"></a></p>

<h5>11.1-2 Exec</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Exec</code>( <var class="Arg">cmd</var>, <var class="Arg">option1</var>, <var class="Arg">...</var>, <var class="Arg">optionN</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">Exec</code> runs a shell in the current directory to execute the command given by the string <var class="Arg">cmd</var> with options <var class="Arg">option1</var>, ..., <var class="Arg">optionN</var>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Exec( "date" );</span>
Thu Jul 24 10:04:13 BST 1997
</pre></div>

<p><var class="Arg">cmd</var> is interpreted by the shell and therefore we can make use of the various features that a shell offers as in following example.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Exec( "echo \"GAP is great!\" &gt; foo" );</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Exec( "cat foo" );</span>
GAP is great!
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Exec( "rm foo" );</span>
</pre></div>

<p><code class="func">Exec</code> calls the more general operation <code class="func">Process</code> (<a href="chap11.html#X7B09033178D1107A"><span class="RefLink">11.1-1</span></a>). The function <code class="func">Edit</code> (<a href="chap6.html#X82E5859C8113BA4D"><span class="RefLink">6.10-1</span></a>) should be used to call an editor from within <strong class="pkg">GAP</strong>.</p>


<div class="chlinkprevnextbot">&nbsp;<a href="chap0.html">[Top of Book]</a>&nbsp;  <a href="chap0.html#contents">[Contents]</a>&nbsp;  &nbsp;<a href="chap10.html">[Previous Chapter]</a>&nbsp;  &nbsp;<a href="chap12.html">[Next Chapter]</a>&nbsp;  </div>


<div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chap8.html">8</a>  <a href="chap9.html">9</a>  <a href="chap10.html">10</a>  <a href="chap11.html">11</a>  <a href="chap12.html">12</a>  <a href="chap13.html">13</a>  <a href="chap14.html">14</a>  <a href="chap15.html">15</a>  <a href="chap16.html">16</a>  <a href="chap17.html">17</a>  <a href="chap18.html">18</a>  <a href="chap19.html">19</a>  <a href="chap20.html">20</a>  <a href="chap21.html">21</a>  <a href="chap22.html">22</a>  <a href="chap23.html">23</a>  <a href="chap24.html">24</a>  <a href="chap25.html">25</a>  <a href="chap26.html">26</a>  <a href="chap27.html">27</a>  <a href="chap28.html">28</a>  <a href="chap29.html">29</a>  <a href="chap30.html">30</a>  <a href="chap31.html">31</a>  <a href="chap32.html">32</a>  <a href="chap33.html">33</a>  <a href="chap34.html">34</a>  <a href="chap35.html">35</a>  <a href="chap36.html">36</a>  <a href="chap37.html">37</a>  <a href="chap38.html">38</a>  <a href="chap39.html">39</a>  <a href="chap40.html">40</a>  <a href="chap41.html">41</a>  <a href="chap42.html">42</a>  <a href="chap43.html">43</a>  <a href="chap44.html">44</a>  <a href="chap45.html">45</a>  <a href="chap46.html">46</a>  <a href="chap47.html">47</a>  <a href="chap48.html">48</a>  <a href="chap49.html">49</a>  <a href="chap50.html">50</a>  <a href="chap51.html">51</a>  <a href="chap52.html">52</a>  <a href="chap53.html">53</a>  <a href="chap54.html">54</a>  <a href="chap55.html">55</a>  <a href="chap56.html">56</a>  <a href="chap57.html">57</a>  <a href="chap58.html">58</a>  <a href="chap59.html">59</a>  <a href="chap60.html">60</a>  <a href="chap61.html">61</a>  <a href="chap62.html">62</a>  <a href="chap63.html">63</a>  <a href="chap64.html">64</a>  <a href="chap65.html">65</a>  <a href="chap66.html">66</a>  <a href="chap67.html">67</a>  <a href="chap68.html">68</a>  <a href="chap69.html">69</a>  <a href="chap70.html">70</a>  <a href="chap71.html">71</a>  <a href="chap72.html">72</a>  <a href="chap73.html">73</a>  <a href="chap74.html">74</a>  <a href="chap75.html">75</a>  <a href="chap76.html">76</a>  <a href="chap77.html">77</a>  <a href="chap78.html">78</a>  <a href="chap79.html">79</a>  <a href="chap80.html">80</a>  <a href="chap81.html">81</a>  <a href="chap82.html">82</a>  <a href="chap83.html">83</a>  <a href="chap84.html">84</a>  <a href="chap85.html">85</a>  <a href="chap86.html">86</a>  <a href="chap87.html">87</a>  <a href="chapBib.html">Bib</a>  <a href="chapInd.html">Ind</a>  </div>

<hr />
<p class="foot">generated by <a href="http://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>