NEST  2.6.0,not_revisioned_source_dir@0
processes.h
Go to the documentation of this file.
1 /*
2  * processes.h
3  *
4  * This file is part of NEST.
5  *
6  * Copyright (C) 2004 The NEST Initiative
7  *
8  * NEST is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * NEST is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef PROCESSES_H
24 #define PROCESSES_H
25 
26 /*
27  SLI's basic process management capabilities
28 */
29 #include <cstdlib>
30 
31 #include "config.h"
32 
33 
34 
35 #include <cstdio>
36 #include <sys/types.h>
37 #include <fstream>
38 #include <string>
39 #include <vector>
40 #include "slimodule.h"
41 #include "slifunction.h"
42 #include "name.h"
43 
44 // A new SLI-Module:
45 class Processes: public SLIModule
46 {
47  // The following concernes the new module: -----------------------
48 
49  public:
50 
51  static const std::string systemerror(SLIInterpreter *); // This will be used to produce systemerror-messages
52 
53  static int fd(std::istream *s);
54  static int fd(std::ostream *s);
55  static int fd(std::ostream &s) {return fd(&s);}
56  static int fd(std::istream &s) {return fd(&s);}
57 
58  static pid_t children_group; // the declaration of a static variable. It will
59  // persist as long as the instantiation of the Processes module lives. Never
60  // confuse declaration and definition of a variable, by the way...
61 
62  const Name signaldict_name; // The name of the signal dictionary
63 
64  // The Names of the signals contained in signal dictionary:
65  // These are the signals defined by the POSIX standard
79 
86 
87 
88  const Name sys_errname; // The name of the variable in errordict, in which the name of a system error will be stored
89  const Name sys_errno; // The corresponding error-number
90 
91  // The Names of the system's error-numberes contained in errordict
99  const Name EDOM_name;
105  const Name EIO_name;
129 
130  // The constructor and destructor for our module object (-if we need them-):
131  Processes(void):
132  signaldict_name("signaldict"),
133  SIGABRT_name("SIGABRT"),
134  SIGALRM_name("SIGALRM"),
135  SIGFPE_name ("SIGFPE"),
136  SIGHUP_name ("SIGHUP"),
137  SIGILL_name ("SIGILL"),
138  SIGINT_name ("SIGINT"),
139  SIGKILL_name("SIGKILL"),
140  SIGPIPE_name("SIGPIPE"),
141  SIGQUIT_name("SIGQUIT"),
142  SIGSEGV_name("SIGSEGV"),
143  SIGTERM_name("SIGTERM"),
144  SIGUSR1_name("SIGUSR1"),
145  SIGUSR2_name("SIGUSR2"),
146 
147  SIGCHLD_name("SIGCHLD"),
148  SIGCONT_name("SIGCONT"),
149  SIGSTOP_name("SIGSTOP"),
150  SIGTSTP_name("SIGTSTP"),
151  SIGTTIN_name("SIGTTIN"),
152  SIGTTOU_name("SIGTTOU"),
153 
154 
155  sys_errname("sys_errname"), // The name of the variable in errordict, in which the name of a system error will be stored
156  sys_errno("sys_errno"), // The corresponding error-number
157 
158  // The Names of the system's error-numberes contained in errordict
159  E2BIG_name("E2BIG"),
160  EACCES_name("EACCES"),
161  EAGAIN_name("EAGAIN"),
162  EBADF_name("EBADF"),
163  EBUSY_name("EBUSY"),
164  ECHILD_name("ECHILD"),
165  EDEADLK_name("EDEADLK"),
166  EDOM_name("EDOM"),
167  EEXIST_name("EEXIST"),
168  EFAULT_name("EFAULT"),
169  EFBIG_name("EFBIG"),
170  EINTR_name("EINTR"),
171  EINVAL_name("EINVAL"),
172  EIO_name("EIO"),
173  EISDIR_name("EISDIR"),
174  EMFILE_name("EMFILE"),
175  EMLINK_name("EMLINK"),
176  ENAMETOOLONG_name("ENAMETOOLONG"),
177  ENFILE_name("ENFILE"),
178  ENODEV_name("ENODEV"),
179  ENOENT_name("ENOENT"),
180  ENOEXEC_name("ENOEXEC"),
181  ENOLCK_name("ENOLCK"),
182  ENOMEM_name("ENOMEM"),
183  ENOSPC_name("ENOSPC"),
184  ENOSYS_name("ENOSYS"),
185  ENOTDIR_name("ENOTDIR"),
186  ENOTEMPTY_name("ENOTEMPTY"),
187  ENOTTY_name("ENOTTY"),
188  ENXIO_name("ENXIO"),
189  EPERM_name("EPERM"),
190  EPIPE_name("EPIPE"),
191  ERANGE_name("ERANGE"),
192  EROFS_name("EROFS"),
193  ESPIPE_name("ESPIPE"),
194  ESRCH_name("ESRCH"),
195  EXDEV_name("EXDEV")
196  {} //Processes constructor
197 
198  ~Processes(void); // clean up dynmem for static variables...
199 
200  // The Module is registered by a call to this Function:
201  void init(SLIInterpreter *);
202 
203  // This function will return the name of our module:
204  const std::string name(void) const;
205 
206  // This function -may- return a string of SLI-commands to be executed for initialization
207  const std::string commandstring(void) const;
208 
209 
210  // ---------------------------------------------------------------
211 
212 
213 
214  // The following concernes the new command(s): -------------------
215 
216  public:
217  // Module contains classes defining new SLI-functions:
218  class ForkFunction: public SLIFunction
219  {
220  public:
221  void execute(SLIInterpreter *) const; // This is all we need.
222  };
224  {
225  public:
226  void execute(SLIInterpreter *) const; // This is all we need.
227  };
229  {
230  public:
231  void execute(SLIInterpreter *) const; // This is all we need.
232  };
233  class KillFunction: public SLIFunction
234  {
235  public:
236  void execute(SLIInterpreter *) const; // This is all we need.
237  };
238  class PipeFunction: public SLIFunction
239  {
240  public:
241  void execute(SLIInterpreter *) const; // This is all we need.
242  };
244  {
245  public:
246  void execute(SLIInterpreter *) const; // This is all we need.
247  };
249  {
250  public:
251  void execute(SLIInterpreter *) const; // This is all we need.
252  };
254  {
255  public:
256  void execute(SLIInterpreter *) const; // This is all we need.
257  };
259  {
260  public:
261  void execute(SLIInterpreter *) const; // This is all we need.
262  };
264  {
265  public:
266  void execute(SLIInterpreter *) const; // This is all we need.
267  };
269  {
270  public:
271  void execute(SLIInterpreter *) const; // This is all we need.
272  };
274  {
275  public:
276  void execute(SLIInterpreter *) const; // This is all we need.
277  };
279  {
280  public:
281  void execute(SLIInterpreter *) const; // This is all we need.
282  };
284  {
285  public:
286  void execute(SLIInterpreter *) const; // This is all we need.
287  };
288 
289 #if defined IS_BLUEGENE_P || defined IS_BLUEGENE_Q
291  {
292  void execute(SLIInterpreter *) const;
293  };
294 #endif
295 
296 #if defined __APPLE__ && HAVE_MACH_MACH_H
298  {
299  void execute(SLIInterpreter *) const;
300  };
301 #endif
302 
304  {
305  public:
306  void execute(SLIInterpreter *) const; // This is all we need.
307  };
309  {
310  public:
311  void execute(SLIInterpreter *) const; // This is all we need.
312  };
314  {
315  public:
316  void execute(SLIInterpreter *) const; // This is all we need.
317  };
319  {
320  public:
321  void execute(SLIInterpreter *) const; // This is all we need.
322  };
323 
324  // Module contains -one- instantiation of each new function-class:
325 
326 public:
341 
342 #if defined IS_BLUEGENE_P || defined IS_BLUEGENE_Q
344 #endif
345 
346 #if defined __APPLE__ && HAVE_MACH_MACH_H
348 #endif
349 
354 };
355 
356 
357 // Description of new SLI-commands:
358 
359 //-----------------------------------------------------------------------------
360 /* BeginDocumentation
361 
362 Name: fork - create a child process of SLI
363 
364 Synopsis: fork -> PID
365 
366 Description: Thin wrapper to the fork() system function
367 
368 Parameters: In : -none-
369  Out: PID(integer) : 0 (for the child)
370  the child's process ID (for the parent)
371 
372 Examples: 1. fork
373  (Well, just kidding...)
374 
375  2. fork 0 eq {(I'm the child!) = quit} {(I'm the parent!) =} ifelse
376  Try this several times. You will notice the child message to appear
377  before or after the parent message "by chance". (Even after the
378  parent's SLI-prompt...)
379 
380 Bugs: -
381 
382 Author: R Kupper
383 
384 FirstVersion: Mar 17 1999
385 
386 Remarks: A full parallel process of SLI is forked.
387  Parent and child will execute in parallel. There is no way to know which
388  will start being executed first.
389  Child inherits all open files, including stdin and stdout, from parent!
390  Thus, calling fork interactively from the SLI-prompt will result in
391  command-line-confusion if both processes end up without quitting.
392  If fork() cannot be executed, an error is raised.
393 
394  SLI-function spoon (processes.sli) is a more convenient wrapper
395  to fork!
396 
397 SeeAlso: spoon, sysexec, getPID, getPPID, getPGRP, wait, waitPID
398 */
399 
400 //-----------------------------------------------------------------------------
401 /* Now Documented with sysexec!
402 
403 Name: sysexec_a - execute a UNIX command
404 
405 Synopsis: CommandArray sysexec -> -
406 
407 Description: Transfer control to a UNIX-Command.
408 
409 Parameters: In : CommandArray (array of strings):
410  An array containing the command to execute. The first element
411  is interpreted as the command, the remaining elements as it's
412  parameters.
413 
414  Out: -whatever will be will be-
415 
416 Examples: -see command sysexec-
417 
418 Bugs: -see command sysexec-
419 
420 Author: R Kupper
421 
422 FirstVersion: Mar 1999
423 
424 Remarks: There is a SLI-wrapper called "sysexec" to this function.
425  -see command sysexec-
426 
427 SeeAlso: sysexec, fork, spoon
428 
429 */
430 
431 //-----------------------------------------------------------------------------
432 /* BeginDocumentation
433 
434 Name: waitPID - wait or check for a child process to terminate
435 
436 Synopsis: PIDin NoHangFlag waitPID -> Status NormalExitFlag PIDout
437  -> 0
438 
439 Description: The waitPID function suspends execution of the calling process
440  until status information for the given child is available,
441  or until delivery of a signal whose action is either to
442  execute a signal-catching function or to terminate the
443  process. If status information is available prior to the call
444  to waitPID, it returns immediately.
445 
446  The waitPID function returns the process ID of the child for
447  which status is being reported.
448  Zero is returned immediately, if the NoHangFlag is set
449  and no status is available.
450 
451  Alternatives: Function waitPID_i_b (undocumented)
452  -> behaviour and synopsis are the same.
453 
454 Parameters: In : PIDin(integer): -1: Wait for any child process.
455  positive: Wait for the specific child whose
456  process ID is equal to PIDin.
457  ( 0: -not supported-)
458  (less than -1: -not supported-)
459 
460  NoHangFlag(boolean):
461  If true, causes waitPID function not to suspend execution
462  of the calling process if status is not immediately
463  available for any of the child processes specified by
464  PIDin. In this case, zero is returned as only result.
465 
466  Out: PIDout(integer):
467  The process ID of the child for which status is being
468  reported.
469 
470  NormalExitFlag(boolean):
471  True, if status is returned for a child that terminated
472  normally, i.e. by a call to exit() or by returning from
473  main(). In that case, the exit code is reported in the Status
474  argument (see below).
475  False, if status is returned for a child that terminated due
476  to a signal that was not caught. In that case, the number of
477  that signal is reported in the Status argument (see below).
478 
479  Status(integer):
480  If NormalExitFlag is true, this reports the child's exit code,
481  i.e. the low-order eight bits of the status argument that the
482  child passed to exit(), or the value the child process
483  returned from main().
484  If NormalExitFlag is false, this reports the number of the
485  signal that caused the termination of the child process. Look
486  up this number in signaldict, to know what it means.
487 
488 Examples:1. {(sleep 3) sysexec} spoon false waitPID
489  2. {(ls) sysexec} spoon false waitPID
490  Note the parent process' SLI-Prompt appearing AFTER execution of the
491  command finished.
492  This is different to the call "{(ls) sysexec} spoon" only.
493  3. 23 false waitPID
494 
495 Bugs: -
496 
497 Author: R Kupper
498 
499 FirstVersion: Apr 13 1999
500 
501 Remarks: The features normally used only by the UNIX-shell-program
502  (such as the WUNTRACED-option) are currently not supported,
503  although values <=0 can be passed through PIDin.
504  See any documentation of POSIX-function waitpid().
505  Discription text is mainly taken from
506  Donald A. Lewine, "POSIX programmer's guide", O'Reilly&Associates,Inc.
507 
508 SeeAlso: wait, spoon, signaldict, getPGRP
509 
510 */
511 
512 //-----------------------------------------------------------------------------
513 /* BeginDocumentation
514 
515 Name: kill - send a signal to another process
516 
517 Synopsis: PID SIGNAL kill -> -
518  PID /SIGNAL kill -> -
519 
520 Description: The "kill" function sends a signal to a process or a group
521  of processes specified by "PID". If the signal is zero,
522  error checking is performed but no signal is actually sent.
523  This can be used to check for a valid PID.
524  SIGNAL may be given either as an integer value or as the
525  literal name of the signal, as found in "signaldict".
526 
527  Alternative: Functions kill_i_i for integer (SIGNAL),
528  kill_i_l for literal (SIGNAL) (both undocumented)
529  -> behaviour and synopsis are the same.
530 
531 Parameters: In : PID(integer):
532  The ID of the process that shall be signalled.
533  If "PID" is greater than zero, "SIGNAL" is sent to the
534  process whose ID is "PID".
535  (If "PID" is negative, "SIGNAL" is sent to all processes
536  whose process group ID is equal to the absolute value
537  of "PID". - Process groups are usually used by the
538  shell program only.)
539 
540  SIGNAL(integer):
541  The number of the signal to be sent.
542  Signal codes are machine-dependent values, so do not
543  rely on any given value! The valid signal codes for
544  your machine are compiled into the "signaldict"
545  dictionary, where they can be looked up by
546  their literal names.
547  The only value you may rely on is zero:
548  If SIGNAL is zero, error checking is performed
549  but no signal is actually sent.
550  This can be used to check for a valid PID.
551 
552  /SIGNAL(literal):
553  The literal name of the signal to be sent.
554  This name is automatically looked up in "signaldict"
555  and substituted to it's corresponding value prior
556  to a call to wait.
557 
558  Out: -none-.
559 
560 Examples: 1. 23 /SIGTERM kill %send TERM signal to Process 23
561 
562  2. %This is equivalent to 1. :
563  signaldict begin
564  23 SIGTERM kill
565  end
566 
567  3. (xterm) 2 system %star an xterm-process
568  /SIGKILL kill %kill it again
569 
570 Bugs: -
571 
572 Author: R Kupper
573 
574 FirstVersion: Apr 27 1999
575 
576 Remarks: "kill" can be used to send ANY signal, but it's most oftenly used
577  to terminate another process. Hence the name.
578  Resolution of literal signal names is done by a trie defined
579  in file processes.sli.
580  Description taken mainly from "POSIX Programmer's Guide",
581  D. Lewine, O'Reilly & Assoc. Inc.
582 
583 
584 SeeAlso: signaldict, system, sysexec, wait, waitPID, spoon, fork, getPPID, getPGRP
585 
586 */
587 
588 //-----------------------------------------------------------------------------
589 /* BeginDocumentation
590 
591 Name: signaldict - Dictionary containing the machine-dependent signal codes.
592 
593 Synopsis: signaldict -> signaldict
594 
595 Description: A SLI dictionary containing the system's valid signal codes.
596  "signaldict" is used in combination with the "kill",
597  "wait" or "waitPID" commands.
598  Signal codes are machine-dependent values, so do not
599  rely on any given value! The valid signal codes for
600  your machine are compiled into the "signaldict"
601  dictionary, where they can be looked up by
602  their literal names.
603 
604 Examples: 1. signaldict /SIGTERM get %get the value for signal SIGTERM
605 
606  2. (xterm) 2 system %start an xterm-prcess
607  signaldict begin %open signal dictionary
608  SIGKILL kill %kill process
609  end %close dictionary
610 
611  3. %This is equivalent to 2. (see description of "kill"):
612  (xterm) 2 system %start an xterm-process
613  /SIGKILL kill %kill it again
614 
615 Bugs: -
616 
617 Author: R Kupper
618 
619 FirstVersion: Apr 16 1999
620 
621 SeeAlso: kill, wait, waitPID, system, sysexec, spoon, fork
622 
623 */
624 
625 //-----------------------------------------------------------------------------
626 /* BeginDocumentation
627 
628 Name: pipe - Open up a pipe
629 
630 Synopsis: pipe -> read_end write_end
631 
632 Description: The pipe function creates a pipe, placing a filestream
633  for the read end and a filestream for the write end of
634  the pipe on the stack.
635  Data can be written to "write_end" and read from "read_end".
636  A read on "read_end" accesses the data written to "write_end"
637  on a first-in-first-out basis.
638 
639 Parameters: In : -none-
640 
641  Out: read_end(ifstream):
642  A filestream open for reading, connected to the read-
643  end of the newly created pipe.
644 
645  write_end(ofstream):
646  A filestream open for writing, connected to the write-
647  end of the newly created pipe.
648 
649 Examples: pipe
650  (Hello Pipe) <- std::endl
651  pop
652  getline =
653 
654 Diagnostics: If a system-error occurs, a code is stored in "sys_errno"
655  (contained in errordict) to identify the error, and
656  "sys_errname" is set to the error message. Then a
657  "SystemError" is raised.
658 
659 Bugs: -
660 
661 Author: R Kupper
662 
663 FirstVersion: May 02 1999
664 
665 Remarks: Description-text taken mainly from "POSIX Programmer's Guide",
666  D. Lewine, O'Reilly & Assoc. Inc.
667 
668  The O_NONBLOCK and FD_CLOEXEC flags are clear on the
669  file descriptors of both streams.
670 
671  Opening a pipe in a single process is next to useless (however,
672  it might be used for buffering data). The usual application
673  is for inter-process-communication: A pipe is opened, and fork
674  is called. The child process inherits both filestreams from
675  the parent. The child will then close one of the streams (say:
676  the read-end), the parent will close the other (say: the write-
677  end). Data may then be transfered from the child to the parent
678  process through the pipe.
679 
680  If the child is to "sysexec" a UNIX command, it may duplicate
681  the pipes's write-end onto its standard "cout" stream using "dup2",
682  thus directing any data written to "cout" into the pipe. It then
683  calles "sysexec". The parent process is thus enabled to read
684  the UNIX-command's standard output from the pipe.
685 
686  Pipes are unidirectional communication channels.
687  For bidirectional communication, two separate pipes must be opened.
688  The "spawn" command provides this functionality.
689 
690 SeeAlso: dup2, available, spawn
691 
692 */
693 
694 //-----------------------------------------------------------------------------
695 /* BeginDocumentation
696 
697 Name: available - check if data is available from an istream
698 
699 Synopsis: istream available -> istream {true|false}
700 
701 Description: "availabe" gives the answer to one question:
702  --Is there at least one character waitng to be read
703  from the istream?--
704  If "available" returns true, it can be safely assumed that
705  reading one character from the given istream is safe,
706  i.e. it will NEITHER BLOCK nor yield EOF or an error.
707 
708  Alternative: Functions available_is (undocumented)
709  -> behaviour and synopsis are the same.
710 
711 Parameters: In: istream: The istream to check.
712  Out: true or false, indicating if data is waiting on the stream.
713 
714 Examples: myfifo available { getline } if % read it data is available.
715 
716 Diagnostics: If a system-error occurs, a code is stored in "sys_errno"
717  (contained in errordict) to identify the error, and "sys_errname" is
718  set to the error message. Then a "SystemError" is raised.
719  The following system errors may be issued, according to the
720  POSIX standard (errors in parantheses are not
721  expected to occur in this routines' context):
722 
723  (EACCES) Search permission is denied for a
724  directory in a files path prefix.
725  (EAGAIN) The ON_NONBLOCK flag is set for a file
726  descriptor and the process would be
727  delayed in the I/O operation.
728  EBADF Invalid file descriptor. (With the current
729  implementation, this indicates trouble
730  getting a fildescriptor from a stream. If
731  it occurs, ask the author for a proper
732  soultion!)
733  (EDEADLK) A fcntl with function F_SETLKW would
734  cause a deadlock.
735  EINTR Function was interrupted by a signal.
736  (EINVAL) Invalid argument.
737  (EMFILE Too many file descriptors are in use by
738  this process.
739  (ENOLCK) No locks available.
740 
741 Bugs: -
742 
743 Author: R Kupper
744 
745 FirstVersion: May 10 1999
746 
747 Remarks: "available" will be typically used with pipes or fifos.
748 
749  There are two possible reasons why "available" may return false:
750  1. There are processes writing to the pipe/fifo, but none
751  of the is currently writing data to it.
752  A subsequent read attempt will block until data becomes
753  available.
754  2. There are no processes writing to the pipe (any longer).
755  A subsequent read attempt will yield EOF.
756  It is NOT possible to tell these possibilities apart! This is
757  not a fault of the implementation of this function. It is generally
758  impossible to do this. The only way to know is to start a read
759  attempt. If it blocks, you know the answer - but you could wait
760  forever. Anyway, there normally is no need to distinguish between
761  these alternatives: Just NEVER try a read attempt, if "available"
762  returned false. Even if temporarily no process was connected to
763  the stream, it will return true as soon as the connection is re-
764  established and data is waiting.
765 
766  "available" just tells you if -one- character may be read safely.
767  It is left to the programmer to assure that a given amount of
768  data (e.g. upto the next linefeed) may be read.
769 
770 SeeAlso: pipe, mkfifo, spawn, eof, in_avail
771 
772 */
773 
774 //-----------------------------------------------------------------------------
775 /* BeginDocumentation
776 
777 Name: getPID - Get ID of the current process
778 
779 Synopsis: getPID -> -
780 
781 Description: Returns the process ID for the calling process.
782 
783 Parameters: -
784 
785 Examples: (I am process #) =only getPID =
786 
787 Diagnostics: A call to "getPID" should never produce an error.
788 
789 Bugs: -
790 
791 Author: R Kupper
792 
793 FirstVersion: May 26 1999
794 
795 SeeAlso: getPPID, getPGRP, fork, spoon, waitPID, kill, system, spawn, shpawn
796 
797 */
798 
799 //-----------------------------------------------------------------------------
800 /* BeginDocumentation
801 
802 Name: getPPID - Get parent ID of the current process
803 
804 Synopsis: getPPID -> -
805 
806 Description: Returns the process parent ID for the calling process.
807 
808 Parameters: -
809 
810 Examples: (I was called by process #) =only getPPID =
811 
812 Bugs: -
813 
814 Author: S Schrader, taken from getPID
815 
816 FirstVersion: Nov 11 2005
817 
818 SeeAlso: getPID, getPGRP, fork, spoon, waitPID, kill, system, spawn, shpawn
819 
820 */
821 
822 //-----------------------------------------------------------------------------
823 /* BeginDocumentation
824 
825 Name: getPGRP - Get process group ID of the current process
826 
827 Synopsis: getPGRP -> -
828 
829 Description: Returns the process group ID for the calling process.
830 
831 Parameters: -
832 
833 Examples: (I am member of process group #) =only getPGRP =
834 
835 Diagnostics: A call to "getPGRP" should never produce an error.
836 
837 Bugs: -
838 
839 Author: R Kupper
840 
841 FirstVersion: Apr 18 2000
842 
843 SeeAlso: fork, getPID, kill
844 
845 */
846 
847 //-----------------------------------------------------------------------------
848 /* BeginDocumentation
849 
850 Name: mkfifo - Create a FIFO special file (named pipe)
851 
852 Synopsis: path mkfifo -> -
853 
854 Description: The "mkfifo" command creates a new FIFO special file named
855  "path". The permission bits are set to "rwx rwx rwx" (full access
856  for anyone). Note that these bits may be modified by the process'
857  file creation mask. (See remarks below.)
858 
859  Alternative: Functions mkfifo_s (undocumented)
860  -> behaviour and synopsis are the same.
861 
862 Parameters: In: path(string):
863  Path name of the FIFO to create.
864 
865 Examples: (/home/kupper/my_fifo) mkfifo
866 
867 Diagnostics: If a system-error occurs, a code is stored in "sys_errno"
868  (contained in errordict) to identify the error, and "sys_errname" is
869  set to the error message. Then a "SystemError" is raised.
870  The following system errors may be issued, according to the
871  POSIX standard:
872 
873  EACCES Search permission denied for a directory in a file's path
874  prefix.
875  EEXIST The named file already exists.
876  ENOENT A file or directory does not exist.
877  ENOSPC No space left on disk.
878  ENOTDIR A component of the specified pathname was not a directory
879  when a directory was expected.
880  EROFS Read-only file system.
881 
882 Bugs: -
883 
884 Author: R. Kupper
885 
886 FirstVersion: Aug 13 1999 (Friday 13th!)
887 
888 Remarks: The FIFO may be used (and has to be opened) like any regular file.
889 
890  In special cases, it might be desireable to change the FIFO's file
891  permission bits. This is not supported by SLI commands.
892  Use UNIX-command "chmod" to change file permissions on the newly
893  created file, or use UNIX-command "umask" to set the process' file
894  creation mask. (See command "system" for issuing UNIX-commands from
895  SLI).
896 
897 SeeAlso: pipe, mkfifo, ifstream, available, ignore, dup2
898 
899 */
900 
901 //-----------------------------------------------------------------------------
902 /* BeginDocumentation
903 
904 Name: setNONBLOCK - Switch between blocking and non-blocking I/O.
905 
906 Synopsis: ifstream {true|false} setNONBLOCK -> ifstream
907 
908 Description: "setNONBLOCK" sets or erases the O_NONBLOCK flag on
909  an input stream. The O_NONBLOCK flag determines, if
910  a read attempt will block when no data is currently
911  available from the stream. By default, a newly
912  created stream has the O_NONBLOCK-Flag erased,
913  meaning that blocking I/O is selected. By erasing
914  O_NONBLOCK, a subsequent read attempt on the stream
915  will yield EOF if no data is availabe.
916 
917  Alternatives: Function setNONBLOCK_is_b (undocumented)
918  -> behaviour and synopsis are the same.
919 
920 Parameters: In : ifstream: The stream to change the flag on.
921  Out: -
922 
923 Examples: cin false setNONBLOCK
924  myfifo true setNONBLOCK % set non-blocking I/O for my fifo.
925 
926 Diagnostics: If a system-error occurs, a code is stored in "sys_errno"
927  (contained in errordict) to identify the error, and "sys_errname" is
928  set to the error message. Then a "SystemError" is raised.
929  The following system errors may be issued, according to the
930  POSIX standard (errors in parantheses are not
931  expected to occur in this routines' context):
932 
933  (EACCES) Search permission is denied for a
934  directory in a files path prefix.
935  (EAGAIN) The ON_NONBLOCK flag is set for a file
936  descriptor and the process would be
937  delayed in the I/O operation.
938  EBADF Invalid file descriptor. (With the current
939  implementation, this indicates trouble
940  getting a fildescriptor from a stream. If
941  it occurs, ask the author for a proper
942  soultion!)
943  (EDEADLK) An fcntl with function F_SETLKW would
944  cause a deadlock.
945  EINTR Function was interrupted by a signal.
946  (EINVAL) Invalid argument.
947  (EMFILE Too many file descriptors are in use by
948  this process.
949  (ENOLCK) No locks available.
950 
951 Bugs: -
952 
953 Author: R Kupper
954 
955 FirstVersion: Oct 20 1999
956 
957 SeeAlso: available, ignore
958 
959 */
960 
961 
962 /*
963 BeginDocumentation
964 
965 Name: ctermid - Return the path to the controlling terminal of the process.
966 
967 Synopsis: ctermid -> (pathname)
968 
969 Remarks: This is a wrapper to the POSIX kernel function ctermid().
970 
971 SeeAlso: isatty
972 */
973 
974 #endif
static int fd(std::istream &s)
Definition: processes.h:56
const Name EBADF_name
Definition: processes.h:95
Definition: processes.h:303
const Name SIGUSR1_name
Definition: processes.h:77
void execute(SLIInterpreter *) const
Definition: processes.cc:542
void init(SLIInterpreter *)
Initialise the module.
Definition: processes.cc:164
const Name ENODEV_name
Definition: processes.h:111
const Name ESRCH_name
Definition: processes.h:127
const Name SIGQUIT_name
Definition: processes.h:74
void execute(SLIInterpreter *) const
Definition: processes.cc:572
CtermidFunction ctermidfunction
Definition: processes.h:351
const Name ERANGE_name
Definition: processes.h:124
GetPPIDFunction getppidfunction
Definition: processes.h:338
GetPGRPFunction getpgrpfunction
Definition: processes.h:339
void execute(SLIInterpreter *) const
Definition: processes.cc:486
const Name ENOTDIR_name
Definition: processes.h:118
const Name SIGFPE_name
Definition: processes.h:68
Definition: processes.h:268
Definition: processes.h:45
Processes(void)
Definition: processes.h:131
const Name ENOEXEC_name
Definition: processes.h:113
const Name EACCES_name
Definition: processes.h:93
const Name SIGUSR2_name
Definition: processes.h:78
Definition: processes.h:253
Dup2_os_isFunction dup2_os_isfunction
Definition: processes.h:335
WaitPIDFunction waitPIDfunction
Definition: processes.h:329
const Name EIO_name
Definition: processes.h:105
const Name SIGTERM_name
Definition: processes.h:76
void execute(SLIInterpreter *) const
Definition: processes.cc:807
AvailableFunction availablefunction
Definition: processes.h:336
Definition: processes.h:243
const Name SIGKILL_name
Definition: processes.h:72
const Name EISDIR_name
Definition: processes.h:106
Definition: processes.h:290
Definition: slifunction.h:35
Definition: processes.h:248
static pid_t children_group
Definition: processes.h:58
Dup2_is_isFunction dup2_is_isfunction
Definition: processes.h:332
Represent strings by ints to facilitate fast comparison.
Definition: name.h:53
const Name SIGTSTP_name
Definition: processes.h:83
Definition: processes.h:258
const Name EFAULT_name
Definition: processes.h:101
static int fd(std::ostream &s)
Definition: processes.h:55
Isatty_isFunction isatty_isfunction
Definition: processes.h:353
PipeFunction pipefunction
Definition: processes.h:331
const Name EMLINK_name
Definition: processes.h:108
Isatty_osFunction isatty_osfunction
Definition: processes.h:352
SetNonblockFunction setnonblockfunction
Definition: processes.h:350
const Name SIGABRT_name
Definition: processes.h:66
void execute(SLIInterpreter *) const
Definition: processes.cc:516
const Name SIGSTOP_name
Definition: processes.h:82
Dup2_os_osFunction dup2_os_osfunction
Definition: processes.h:333
Definition: processes.h:223
void execute(SLIInterpreter *) const
Definition: processes.cc:859
MemoryThisjobBgFunction memorythisjobbgfunction
Definition: processes.h:343
void execute(SLIInterpreter *) const
Definition: processes.cc:743
void execute(SLIInterpreter *) const
Definition: processes.cc:712
const Name SIGSEGV_name
Definition: processes.h:75
void execute(SLIInterpreter *) const
Definition: processes.cc:325
Definition: processes.h:218
~Processes(void)
Definition: processes.cc:269
Definition: processes.h:278
Definition: processes.h:273
void execute(SLIInterpreter *) const
Definition: processes.cc:432
const Name SIGCONT_name
Definition: processes.h:81
const Name EINVAL_name
Definition: processes.h:104
Definition: processes.h:313
const Name sys_errno
Definition: processes.h:89
Definition: interpret.h:69
const Name SIGHUP_name
Definition: processes.h:69
const Name EBUSY_name
Definition: processes.h:96
const Name ENOTTY_name
Definition: processes.h:120
Definition: processes.h:318
const Name EPIPE_name
Definition: processes.h:123
Definition: processes.h:228
const std::string commandstring(void) const
Return sli command sequence to be executed for initialisation.
Definition: processes.cc:159
const Name EINTR_name
Definition: processes.h:103
const Name EAGAIN_name
Definition: processes.h:94
const Name SIGTTOU_name
Definition: processes.h:85
Definition: processes.h:233
const Name EFBIG_name
Definition: processes.h:102
void execute(SLIInterpreter *) const
Definition: processes.cc:883
void execute(SLIInterpreter *) const
Definition: processes.cc:697
static const std::string systemerror(SLIInterpreter *)
Definition: processes.cc:106
const Name SIGTTIN_name
Definition: processes.h:84
const Name SIGCHLD_name
Definition: processes.h:80
const Name EPERM_name
Definition: processes.h:122
Definition: processes.h:283
void execute(SLIInterpreter *) const
Definition: processes.cc:776
ForkFunction forkfunction
Definition: processes.h:327
Definition: processes.h:263
GetPIDFunction getpidfunction
Definition: processes.h:337
void execute(SLIInterpreter *) const
Definition: processes.cc:280
Dup2_is_osFunction dup2_is_osfunction
Definition: processes.h:334
const Name EEXIST_name
Definition: processes.h:100
const Name SIGINT_name
Definition: processes.h:71
Definition: processes.h:308
Base class for all SLI Interpreter modules.
Definition: slimodule.h:34
const Name ENOMEM_name
Definition: processes.h:115
const Name ENXIO_name
Definition: processes.h:121
static int fd(std::istream *s)
Definition: processes.cc:120
const Name E2BIG_name
Definition: processes.h:92
const Name EDOM_name
Definition: processes.h:99
const std::string name(void) const
Return name of the module.
Definition: processes.cc:154
const Name ENAMETOOLONG_name
Definition: processes.h:109
Definition: processes.h:297
void execute(SLIInterpreter *) const
Definition: processes.cc:366
void execute(SLIInterpreter *) const
Definition: processes.cc:459
const Name ENOENT_name
Definition: processes.h:112
void execute(SLIInterpreter *) const
Definition: processes.cc:798
Sysexec_aFunction sysexec_afunction
Definition: processes.h:328
const Name SIGILL_name
Definition: processes.h:70
const Name EXDEV_name
Definition: processes.h:128
const Name ENOSPC_name
Definition: processes.h:116
MkfifoFunction mkfifofunction
Definition: processes.h:340
const Name sys_errname
Definition: processes.h:88
void execute(SLIInterpreter *) const
Definition: processes.cc:850
const Name ESPIPE_name
Definition: processes.h:126
const Name ECHILD_name
Definition: processes.h:97
void execute(SLIInterpreter *) const
Definition: processes.cc:598
const Name ENOLCK_name
Definition: processes.h:114
const Name ENFILE_name
Definition: processes.h:110
Definition: processes.h:238
void execute(SLIInterpreter *) const
Definition: processes.cc:728
const Name EROFS_name
Definition: processes.h:125
const Name ENOTEMPTY_name
Definition: processes.h:119
KillFunction killfunction
Definition: processes.h:330
const Name EDEADLK_name
Definition: processes.h:98
MemoryThisjobDarwinFunction memorythisjobdarwinfunction
Definition: processes.h:347
const Name SIGPIPE_name
Definition: processes.h:73
const Name signaldict_name
Definition: processes.h:62
const Name ENOSYS_name
Definition: processes.h:117
const Name SIGALRM_name
Definition: processes.h:67
const Name EMFILE_name
Definition: processes.h:107