File: processfork.c

package info (click to toggle)
yodl 4.04.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,720 kB
  • sloc: ansic: 7,803; perl: 683; cpp: 570; sh: 411; xml: 190; makefile: 164
file content (24 lines) | stat: -rw-r--r-- 958 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "process.ih"

void process_fork(Process *pp)
{
                /* NB: ALERT messages terminate the current process     */
    int readPipe[2];                    /* Yodl reads from this pipe    */
    int writePipe[2];                   /* Yodl writes to this pipe     */

    if (pipe(readPipe) != 0 || pipe(writePipe) != 0)
        if (message_show(MSG_ALERT))
            message("%s: Can't construct pipes", pp->d_fname);

    pp->d_pid = fork();                 /* Do the fork                  */

    if (pp->d_pid == -1)                /* fork fails                   */
        if (message_show(MSG_ALERT))
            message("%s: Can't fork(%s)", pp->d_fname, pp->d_short_cmd);

    if (!pp->d_pid)                     /* No pid: so child process     */
        exit(p_child(pp, writePipe, readPipe));

                                        /* Got pid: so parent process   */
    p_check_status(pp, p_parent(pp, readPipe, writePipe));
}