source: web/old/remctl-2.14/tests/data/cmd-background.c @ f6f3e91

web
Last change on this file since f6f3e91 was f6f3e91, checked in by Jessica B. Hamrick <jhamrick@…>, 15 years ago

Preserve directory hierarchy (not sure what happened to it)

  • Property mode set to 100644
File size: 1000 bytes
Line 
1/*
2 * Small C program that outputs a string, forks off a process that sleeps for
3 * ten seconds and outputs another string, and meanwhile immediately exits.
4 * Used to test that remctld stops listening as soon as its child has exited
5 * and doesn't wait forever for output to be closed.
6 *
7 * Written by Russ Allbery <rra@stanford.edu>
8 * Copyright 2007 Board of Trustees, Leland Stanford Jr. University
9 *
10 * See LICENSE for licensing terms.
11 */
12
13#include <config.h>
14#include <portable/system.h>
15
16int
17main(void)
18{
19    pid_t pid;
20    FILE *pidfile;
21
22    printf("Parent\n");
23    fflush(stdout);
24    pid = fork();
25    if (pid < 0) {
26        fprintf(stderr, "Cannot fork child\n");
27        exit(1);
28    } else if (pid == 0) {
29        pidfile = fopen("data/cmd-background.pid", "w");
30        if (pidfile != NULL) {
31            fprintf(pidfile, "%lu\n", (unsigned long) getpid());
32            fclose(pidfile);
33        }
34        sleep(10);
35        printf("Child\n");
36        exit(0);
37    }
38    return 0;
39}
Note: See TracBrowser for help on using the repository browser.