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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
|
includefile(include/header)
COMMENT(manpage, section, releasedate, archive, short name)
manpage(FBB::Process)(3bobcat)(_CurYrs_)(libbobcat-dev__CurVers_)
(Running Child Processes)
manpagename(FBB::Process)(Runs external programs)
manpagesynopsis()
bf(#include <bobcat/process>)nl()
Linking option: tt(-lbobcat)
manpagedescription()
The bf(FBB::Process) class offers an extensive interface to calling
external programs and/or scripts from a bf(C++) program (so-called
em(child-processes)). The class offers an easy to use, stream-based interface
to the standard input, standard output and standard error streams of child
processes.
Objects of the tt(class Process) use standard process-executing functions,
like members of the bf(execl)(1) family or bf(sh)(1) to execute child
processes. Thus, child processes can be executable programs or
em(shell-scripts).
The standard input, output and error streams of child processes may
be accessed through their tt(Process) parent objects. Input expected by child
processes may be inserted by tt(Process) objects, and output generated by
child processes may be extracted from tt(Process) objects.
When using (output) redirection with the tt(USE_SHELL) path specification (see
below for the path and IOMode specifications), the tt(IGNORE_COUT IOMode) (and
possibly tt(IGNORE_CERR)) should normally be specified.
tt(Process) objects may repeatedly be used to execute the same or different
child processes. Before the next child process is started, the tt(Process)
object first terminates its currently active child process. Alternatively, a
currently active child process is automatically ended if the tt(Process)
object goes out of scope, if its tt(stop) or tt(eoi) (end-of-information)
member is called, or if the tt(eoi) manipulator is inserted into the
tt(Process) object.
Programs called as child processes may be specified when constructing a
tt(Process) object or by using tt(Process's setCommand)
member. tt(Process) constructors (or tt(Process set)-members) never start
child processes. Child processes are started through tt(start) members or the
assignment operator.
Child processes may receive information at their standard input streams
through information inserted into tt(Process) objects. In these cases the
tt(Process) objects must inform their child processes that they have received
all input. For this the tt(close) or tt(eoi) member or the tt(eoi) manipulator
can be used. After calling the tt(close) member, the tt(waitForChild) member
should be called as well. This is not necessary if either the tt(eoi) member
or the tt(eoi) manipulator is used.
If tt(waitForChild) is not called (but information sent to the child which
could not be fully processed by the child process in case the child process
terminated as a result of the tt(Process) object going out of scope), then the
operating system issues a tt(Broken pipe) message, indicating that information
in a pipe was lost.
Arguments passed to child processes may be surrounded by double
or single quotes. Arguments surrounded by double quotes have their double
quotes removed, while interpreting any escape-sequences that may have been
used within. Arguments surrounded by single quotes have their single quotes
removed, while accepting their content as-is. In addition unquoted
escape-sequences may be specified: those escape sequences are evaluated and
replaced by their intended characters (e.g., tt(\100) is converted to tt(@)).
A full command specification may be surrounded by backtics
(tt(`)-characters). These backtick characters are removed by the tt(Process)
object when the command is started.
Child processes may be allowed a limited amount of time (in seconds) to
complete. By default no time limit is imposed upon child processes.
By default the standard input, output and error streams of child processes are
accessed through their tt(Process) parent processes: information inserted into
the tt(Process) object is forwarded to the child process's standard input
stream, information sent by the child process to its standard output stream
can be extracted from its parent tt(Process) object, and information sent by
the child process to its standard error stream may be obtained through
tt(Process's childErrStream) member.
If the parent and child processes have agreed on some communication process,
then information may alternatingly be sent to and received from the child
process through the tt(Process's ostream) and tt(istream)
facilities. Alternatively, unspecified amounts of information written by child
processes may be processed by separate threads (cf. this manual page's
bf(EXAMPLES) section).
tt(Process) objects use tt(Pipe) objects (cf. bf(pipe)(3bobcat)) for
communication with its child processes. To ensure that these pipes are
properly closed the members tt(waitForChild, stop) or the tt(eoi) manipulator
should be used. Once a tt(Process) object ceases to exist pipes to its child
process are also closed.
includefile(include/namespace)
manpagesection(INHERITS FROM)
bf(FBB::Fork)(3bobcat) (private), nl()
bf(FBB:IOStream)(3bobcat), and by implication: bf(FBB::Eoi), nl()
bf(FBB:ProcessEnums)
The tt(struct ProcessEnums) defines enumerations and support functions which
are used by several classes. Its enumerations are documented below; there is
no separate bf(ProcessEnums) man-page.
manpagesection(ENUMERATIONS)
bf(enum ProcessType):nl()
The bf(enum ProcessType) defines how a child process is started or
located. Its values are specified at constructor-time or through the
tt(setProcessType) member. This enumeration defines the following symbolic
constants:
itemization(
itb(NO_PATH)
The program specified as child process is started as specified,
without searching the elements of the tt(PATH) environment
variable.
itb(USE_PATH)
The elements of the tt(PATH) environment variable are used when
locating the program specified as child process.
itb(USE_SHELL)
The program specified as child process is called using tt(/bin/sh
-c). When (output) redirection is used with the specified command
the tt(IGNORE_COUT IOMode) (and possibly also the tt(IGNORE_CERR
IOMode)) should be specified.
)
bf(enum IOMode):nl()
Values of the tt(enum IOMode) are used to define which of the child
process's standard streams can be accessed through the tt(Process) object. Its
symbolic constants may be combined using the tt(bit_or) operator. By default
tt(CIN | COUT | CERR) is used (see below).
The following symbolic constants are available:
itemization(
itb(ALL)
Shortcut for bf(CIN | COUT | CERR).
itb(CIN)
Information inserted into the tt(Process) object is forwarded to
its child process. If this is not required then tt(CIN) should
not be specified.
itb(CERR)
Information written by the child process to its standard error
stream is accessible through tt(Process's childErrStream) member.
If this is not required then tt(CERR) should not be specified.
itb(COUT)
Information written by the child process to its standard output
stream may be directly be extracted from the tt(Process) object,
or from its tt(childOutStream) member. If this is not required
then tt(COUT) should not be specified.
itb(DIRECT)
When starting a child process (see below at the member tt(start))
the current process (i.e., the program defining the tt(Process)
object) is replaced by the child process, inheriting the current
process's standard input and output streams. If this mode is
specified in combination with any other tt(IOMode) (except for
tt(NONE), see below) an tt(std::invalid_argument) exception is
thrown.
itb(IGNORE_CERR)
Information written by the child process to its standard error
stream is sent to tt(/dev/null). An tt(std::invalid_argument)
exception is thrown if this mode is specified in combination with
bf(DIRECT, CERR) and/or bf(MERGE_COUT_CERR).
itb(IGNORE_COUT)
Information written by the child process to its standard output
stream is sent to tt(/dev/null). An tt(std::invalid_argument)
exception is thrown if this mode is specified in combination with
bf(COUT, DIRECT) and/or bf(MERGE_COUT_CERR).
itb(IGNORE_COUT_CERR)
Shortcut for tt(IGNORE_CERR | IGNORE_COUT).
itb(MERGE_COUT_CERR)
Information extracted from the tt(Process) object is written by the
child process to its standard output and standard error streams.
An tt(std::invalid_argument) exception is thrown if this mode is
specified in combination with bf(COUT, CERR, DIRECT, IGNORE_COUT)
or tt(IGNORE_CERR).
itb(NONE)
The tt(Process) object does not extract information from or insert
information into the standard streams of its child process. The
child process reads the same standard input stream and writes the
same standard output streams as its parent tt(Process)
object. When this mode is specified in combination with other
tt(IOMode) values it is silently ignored.
)
bf(enum ChildOutput):nl()
The tt(ChildOutput) enumeration defines values returned by the
tt(available) member (see below) indicating to which standard stream the
child process has written information. This enumeration defines the following
values:
itemization(
itb(NOTHING_AVAILABLE)
The child process did not (yet) write any information to its
standard streams;
itb(CHILD_COUT)
The child process wrote information to its standard output
stream which is waiting for extraction.
itb(CHILD_CERR)
The child process wrote information to its standard error stream
which is waiting for extraction.
)
The latter two values may be combined using the tt(bit_or) operator. The
tt(bit_and) operator,returning a tt(bool) value can be used to test whether
information on a specific output stream is available.
manpagesection(PROCESS PARAMETERS)
Four process parameters may be specified: the sizes of the stream buffers
which are used when communicating with child processes; to specify which of
the standard streams of child processes can be accessed from the tt(Process)
object combinations of tt(IOMode) values are used; to specify how child
programs are found a tt(ProcessType) value is used; to specify the maximum
time (in seconds) the child program is allowed to run a tt(size_t) values is
used.
By default, the stream buffers hold 200 bytes; all the child's standard
streams (standard input, output and error) are accessible from the tt(Parent)
process; the tt(PATH) environment variable is em(not) used to locate the child
program; and the child processes will be allowed an unlimited amount of time
to run.
After constructing a tt(Process) object all default parameters may be
modified. These parameters may either be altered for a single process or a
tt(Process) object's general defaults may be modified. The tt(set*) members
(see below) may be used to change the default process parameters. When
parameters are specified otherwise, they will only be active for the next
process.
manpagesection(CONSTRUCTORS)
The command provided to the following constructors may be the
(initial part of the) specification of an external program to run. When the
program is eventually started it may start and end with a em(back-tick)
(tt(`)). The back-ticks will be removed just before the specified program is
executed.
Child processes are em(not) started automatically following tt(Process)
object constructions. A tt(start) member or the assignment operator (see
below) is used to start the specified child process.
Constructors expecting an tt(IOMode) argument may be provided with
multiple tt(IOMode) values by combining them using the bit-or operator.
After constructing a tt(Process) object its parameters can be changed
using tt(set)-member functions, function call operators or tt(start) members.
itemization(
itb(Process(std::string const &cmd = ""))
This constructor is used to specify the (initial part of a) command to
execute from a tt(Process) object. Default values are used for the
process parameters (see section bf(PROCESS PARAMETERS)).
itb(Process(IOMode mode, std::string const &cmd = ""))
This constructor requires the specification of the object's
bf(IOMode), and it can be used to specify the (initial part of
a) command to execute from a tt(Process) object. Default values
are used for the remaining process parameters (see section bf(PROCESS
PARAMETERS)).
itb(Process(IOMode mode, ProcessType type, std::string const &cmd = ""))
This constructor requires the specification of the object's
bf(IOMode) and tt(ProcessType), and it can be used to specify the (initial
part of a) command to execute from a tt(Process) object. Default values are
used for the remaining process parameters (see section bf(PROCESS
PARAMETERS)).
itb(Process(IOMode mode, ProcessType type, size_t timeLimit,
std::string const &cmd = ""))
This constructor requires the specification of the object's
bf(IOMode), tt(ProcessType), and child process time limit. The (initial part
of a) command to execute from a tt(Process) object may optionally be
specified. The default process parameter is used for the sizes of the
internally used stream buffers (see section bf(PROCESS PARAMETERS)).
itb(Process(IOMode mode, ProcessType type, size_t timeLimit, size_t
bufferSize, std::string const &cmd = ""))
This constructor requires the specification of the object's
bf(IOMode), tt(ProcessType), child process time limit, and size of the
internally used stream buffers. The (initial part of a) command to execute
from a tt(Process) object may optionally be specified. Note that this
constructor's tt(mode) parameter does not accept a tt(size_t) argument.
)
Copy and move constructors (and assignment operators) are not available.
manpagesection(OVERLOADED OPERATORS)
itemization(
itb(Process &operator<<(Type value))
This operator inserts tt(value) into the child's standard input
stream. I.e., the child process reads tt(value) from its standard input. A
value of any type that can be inserted into an tt(ostream) can be inserted
into a tt(Process) object. Nothing happens if the member is used when the
child process has terminated. Manipulators like tt(std::endl) are also
supported. The behavior of this operator is undefined unless tt(IOMode CIN)
was specified.
itb(Process &operator>>(Type value))
This operator extracts tt(value) from the child's standard output
stream and optionally (if tt(IOMode MERGE_COUT_CERR) was specified) from the
child's error stream. I.e., tt(value) may be extracted from tt(Process)
objects. A value of any type that can be extracted from an tt(istream)
can be extracted from a tt(Process) object. Nothing happens if the member is
used when the child process has terminated. The behavior of this operator is
undefined unless tt(IOMode COUT) or tt(MERGE_COUT_CERR) was specified.
itb(Process &operator+=(std::string const &))
This operator adds the provided tt(std::string) object to the currenly
defined command specification of a tt(Process) object. The member
tt(operator+=) does not add a separating blank space between the currently
stored command specification and the text to append. It merely adds its
right-hand side string to the command stored so far. It does not affect a
currently running child process.
itb(int operator=(std::string const &cmd))
The tt(operator=) member defines tt(cmd) as the stored command in
a tt(Process) object.
Before starting the child process a possibly active child process is first
stopped by calling tt(stop). It returns tt(stop)'s return value. Immediately
after calling tt(stop) the new command (tt(cmd)) is started. If stopping and
restarting another command should be separate actions then use tt(stop),
followed by tt(setCommand), followed by calling an appropriate overloaded
version of the member tt(start) (tt(start()) uses the object's current
tt(IOMode, ProcessType,) and time limit).
itb(Process &operator()(IOMode mode))
This operator changes the the tt(Process) object's tt(IOMode)
parameter. A reference to the tt(Process) object is returned, allowing
constructions like
verb(
process(Process::COUT) = "/bin/cat";
)
to start a new child process with the specified tt(IOMode).
itb(Process &operator()(IOMode mode, ProcessType type))
This operator changes the tt(Process) object's tt(IOMode) and
tt(ProcessType) process parameters.
itb(Process &operator()(IOMode mode, ProcessType type, size_t timeLimit))
This operator changes the tt(Process) object's mentioned process
parameters. The currently specified default size of the stream buffers is kept
as-is.
itb(Process &operator()(IOMode mode, ProcessType type, size_t timeLimit,
size_t bufferSize))
This operator changes all of the tt(Process) object's process
parameters.
itb(Process &operator|(Process &lhs, Process &rhs))
This operator implements process em(piping): information sent b
tt(lhs) to its standard output becomes the tt(rhs)'s standard input. The
operator returns tt(rhs).
This operator mimics the piping-operator supported by most command-shell
programs and should not be confused with the binary-or operator. The operator
starts the tt(lhs)'s child process, but the tt(rhs)'s child
process (and thus pipe processing) must explicitly be started.
Since tt(operator|) is left-associative and tt(rhs) is returned piping can
be em(chained), allowing constructions like tt(p1 | p2 | p3), where tt(p1, p2)
and tt(p3) are tt(Process) objects.
The following idiom can be used to start the execution of a chain of
processes: tt((p1 | p2 | p3).start()). Alternatively, the following two-step
procedure can be used:
verb(
p1 | p2 | p3;
p3.start();
)
If tt(p1) specifies tt(Process::CIN) then this tt(IOMode) is forwared to
the final process of the chain of processes. It is not necessary to specify
tt(Process::CIN) for tt(p3). In fact, most tt(IOMode) flags of processes
passed to tt(operator|) are ignored or modified. Acceptable tt(IOModes) are
tt(Process::IGNORE_CERR) and tt(Process::CERR) (accepted for all processes),
tt(Process::CIN) (accepted for the first process of the chain), and
tt(Process::COUT) (for the last process of the chain).
bf(Note:) when connecting a series of processes using tt(operator|) all input
and output (except for the standard error streams) is handled through the last
process: if tt(Process::CIN) is specified for the first process then this mode
is transferred to the last process, so information inserted into the last
process enters the pipe through the first process's standard input.
The next example illustrates how input can be inserted into the first
process from a main process and sent to the standard output stream by the
final process:
verb(
using namespace std;
using namespace FBB;
Process p1(Process::CIN, "/bin/cat");
Process p2("/bin/cat");
Process p3(Process::NONE, "/bin/cat");
p1 | p2 | p3;
p3.start();
p3 << cin.rdbuf() << eoi;
)
When joining multiple commands using the piping operator (tt('|')), the
process type tt(USE_SHELL) is not required, even though process-piping is
commonly used as a shell-feature. tt(Process's operator|) handles I/O piping
itself, and thus can avoid the additional shell process.
)
manpagesection(MEMBERS)
itemization(
itb(bool active())
This member returns tt(true) if the child process is currently running
and tt(false) if not.
itb(size_t available())
This member returns immediately. Its return value indicates whether
any information can be obtained from the child process as value(s) from the
tt(enum ChildOutput). tt(NOTHING_AVAILABLE) is returned if no information is
ready for extraction. tt(CHILD_COUT) is returned if information from the child
process's standard output stream is available; tt(CHILD_CERR) is returned if
information from the child process's standard error stream is available;
tt(CHILD_COUT | CHILD_CERR) is returned if information from both the standard
output and standard error streams is available. The tt(bit_and) operator,
returning a tt(bool) value, can be used to determine which stream has any
pending information. E.g.,
verb(
if (process.available() & Process::CHILD_COUT)
cout << "Process has child standard output available";
)
itb(size_t bufSize() const)
This member returns the default size of the stream buffers that are
used for communication with child processes. If called while a child process
is actually running, then the value returned by this member may differ from
the value that was actually used when starting the child process, as the
default value may be altered by a function call operator just before starting
the child process.
itb(std::istream &childErrStream())
If tt(Process::CERR) was specified then this member interfaces
to the child's standard error stream. By extracting the information from
tt(childErrStream) the parent process retrieves the information sent by its
child process to its standard error stream.
itb(std::istream &childOutStream())
If tt(Process::COUT) or
tt(Process::MERGE_COUT_CERR) was specified then this member interfaces
to the child's standard output stream. By extracting the information from
tt(childOutStream) the parent process retrieves the information sent by its
child process to its standard output stream. Alternatively, this information
may directly be extracted from the tt(Process) object itself, but this member
does not require the use of a tt(static_cast) to disambiguate the intended
stream buffer in statements like
verb(
cout << process.childOutStream().rdbbuf()
)
itb(void close())
This member closes the child's input stream. In situations where the
child continuously reads information from its standard input stream this
member can be used to inform the child process that input has terminated. This
member should only be used when tt(IOMode CIN) was specified for the currently
running child process; otherwise its behavior is undefined. Alternatively, the
tt(eoi) member or manipulator may be used.
itb(int eoi())
This member closes the child's input stream, and then calls
tt(waitForChild) to wait for the child process to end. In situations where the
child continuously reads information from its standard input stream this
member can be used to inform the child process that input has terminated. This
member should only be used when tt(IOMode CIN) was specified for the currently
running child process; otherwise its behavior is undefined. Alternatively, the
tt(close) member or tt(eoi) manipulator may be used. The exit-status of the
called child process is returned.
itb(int exitStatus() const)
After calling tt(eoi) or inserting the tt(eoi) manipulator into the
tt(Process) object this member returns the child process's exit status. In
other cases the value returned by tt(exitStatus) is not defined, and
tt(waitForChild) should be used.
itb(IOMode ioMode() const)
This member returns the default tt(IOMode). If called while a child
process is actually running, then the value returned by this member may differ
from the value that was actually used when starting the child process, as the
default value may be altered by a function call operator just before starting
the child process.
itb(ProcessType processType() const)
This member returns the default tt(ProcessType) of child proceses. If
called while a child process is actually running, then the value returned by
this member may differ from the value that was actually used when starting the
child process, as the default value may be altered by a function call operator
just before starting the child process.
itb(size_t timeLimit() const)
This member returns the default time limit (in seconds) of child
processes. A return value of zero indicates that no time limit is enforced. If
called while a child process is actually running, then the value returned by
this member may differ from the value that was actually used when starting the
child process, as the default value may be altered by a function call operator
just before starting the child process.
itb(void setBufSize(size_t bufSize))
This member changes the default stream buffer size that is used for
communication with child processes. A zero byte buffer size is silently
changed into one. The new default value will be used when starting the next
child process.
itb(void setCommand(std::string const &cmd))
The tt(setCommand) member (re)defines the (initial part of a) child
process command specification.
This member does not actually start the child process, and tt(operator+=)
may be used to append additional text to the command specification. Also, this
member may be used when a child process is currently active: its use does not
affect a currently running child process.
itb(void setIOMode(iomode mode))
This member changes the default tt(IOMode). The new default value will
be used when starting the next child process.
itb(void setProcessType(ProcessType type))
This member changes the default tt(ProcessType). The new default value
will be used when starting the next child process.
itb(void setTimeLimit(size_t timeLimit))
This member changes the default execution time limit (in seconds). No
time limit will be imposed upon child processes if tt(timeLimit 0) is
specified. The new default value will be used when starting the next child
process.
itb(void start())
The currently specified command is started using the tt(Process)
object's process parameters.
Having specified a command to start, the first white-space delimited
element of the specified command is used as the name of the program to
start. If the program should be called through bf(sh)(1), the tt(USE_SHELL
ProcessType) or a tt(system) member should be used.
If a child process does not terminate by itself, then it is terminated
when it has run for its alloted time; when the tt(Process) object's tt(start)
or tt(stop) members are called; when the object's assignment operator is used;
or when the object goes out of scope.
Alternatively, the member tt(waitForChild) (see below) may have to be
called to end a running process.
itb(void start(IOMode mode))
The currently specified command is started using the specified
tt(IOMode), but otherwise using the currently configured tt(Process) object's
process parameters. The specified tt(IOMode) is only used for the child
process that is started by this member.
itb(void start(IOMode mode, ProcessType type))
The currently specified command is started using the specified
tt(IOMode) and tt(ProcessType), but otherwise using the currently configured
tt(Process) object's process parameters. The specified process parameter
values are only used for the child process that is started by this member.
itb(void start(size_t mode, Program program, size_t timeLimit))
The currently specified command is started using the specified
tt(IOMode), tt(ProcessType), and time limit (silently converting the tt(size_t
mode) to an tt(IOMode) value), and using the currently configured tt(Process)
object's stream buffer size parameter. The specified process parameter values
are only used for the child process that is started by this member.
itb(void start(IOMode mode, Program program, size_t timeLimit, size_t
bufferSize))
The currently specified command is started using the specified process
parameters. The specified parameter values are only used for the child process
that is started by this member.
itb(void showMode(char const *lab) const)
This member displays the label tt(lab), followed by the current
process ID, followed by the child process's process ID, followed by a textual
representation of the currently active tt(IOMode).
itb(std::string const &str() const)
This member returns the content of the current child process command
specification. It shows the command as it will be (or has been) executed by
tt(start), tt(system) or the assignment operator.
itb(void system())
This member executes the currently stored command as a command to
bf(sh)(1). When using tt(system) redirections can be included in the command
itself (this renders the redirected streams implied by the current bf(IOMode))
useless. The currently set process parameters are used when bf(sh)(1) is
executed.
itb(void system(IOMode mode))
This member executes the currently stored command as a command to
bf(sh)(1) (cf. tt(system) above) using the specified tt(IOMode) rather than
the current default tt(IOMode) setting.
itb(void system(IOMode mode, size_t timeLimit))
This member executes the currently stored command as a command to
bf(sh)(1) (cf. tt(system) above) using the specified tt(IOMode) and time
limit.
itb(void system(IOMode mode, size_t timeLimit, size_t bufSize))
This member executes the currently stored command as a command to
bf(sh)(1) (cf. tt(system) above) using the specified tt(IOMode), time
limit, and stream buffer size values.
itb(int stop())
This member terminates a currently active child process. The child
process is twice sent a tt(SIG_TERM) signal, followed by a tt(SIG_KILL)
signal. This member returns the exit-value of the child process that was
stopped. Its operation and return value are undefined if called without a
running child process.
Following tt(stop) a new command may be called using tt(start, system) or
the assignment operator (see earlier). Those members first calls tt(stop).
When the intention is to start another child process, then there's no need to
call tt(stop) explicitly. Also, tt(stop) is called when the tt(Process) object
goes out of scope.
itb(int waitForChild())
This member calls the identically named member from the class
tt(FBB::Fork), waiting for a
child process to end. It is called to prevent premature termination of a
child process before calling tt(stop). It is not always necessary to call
tt(waitForChild). E.g., when a process writes to its standard output stream
and all output has been read then the child process can be stopped without
calling tt(waitForChild).
)
manpagesection(MANIPULATOR)
itemization(
itb(FBB::eoi)
This manipulator may be inserted into a tt(Process) object for which
tt(IOMode CIN) was specified. It closes the child's input stream, and then
calls tt(waitForChild) to wait for the child process to end. In situations
where the child continuously reads information from its standard input stream
this member can be used to inform the child process that input has
terminated. Alternatively, tt(Process) object's tt(close) or tt(eoi) members
may be used.
)
manpagesection(EXAMPLES)
The first example shows how a program only producing output can be
called. Its child process simply is tt(/bin/ls):
verbinsert(//CODE ../../process/driver/ls.cc)
The next example shows how a child program can be given a limited amount
of execution time: lines entered at the keyboard are echoed to the standard
output stream for at most 5 seconds:
verbinsert(//CODE ../../process/driver/limit.cc)
The final example shows how multi threading can be used to access the
child program's standard output and standard error streams through the
tt(Process) object:
verbinsert(//CODE ../../process/driver/all.cc)
Additional examples are found in the distribution's
tt(bobcat/process/driver) directory.
manpagefiles()
em(bobcat/process) - defines the class interface
manpageseealso()
bf(bobcat)(7), bf(execle)(3), bf(exec)(3bobcat),
bf(coutextractor)(3bobcat), bf(cerrextractor)(3bobcat), bf(fork)(3bobcat),
bf(cininserter)(3bobcat), bf(iostream)(3fork), bf(sh)(1),
bf(stdextractor)(3bobcat).
manpagebugs()
With the release of Bobcat 1.21.1 the class tt(Process) was completely
rewritten. The new implementation, however, should not affect existing
programs other than that tt(Process) will no longer impose a limited
time-to-live upon child processes. The interface was enlarged, but this should
not affect existing programs. The internal organization of the tt(Process)
class em(has) changed though, requiring recompilation of sources defining
tt(Process) class type objects and linking dynamically to the tt(Bobcat)
library.
With the release of Bobcat 2.11.0 another major modification of
tt(Process) was realized. Although tt(Process)'s internal organization was
again modified this does not affect exeisting programs using tt(Process)
objects. No recompilation of existing sources using tt(Process) is required.
includefile(include/trailer)
|