File: test-system2.c

package info (click to toggle)
r-base 4.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 112,924 kB
  • sloc: ansic: 291,338; fortran: 111,889; javascript: 14,798; yacc: 6,154; sh: 5,689; makefile: 5,239; tcl: 4,562; perl: 963; objc: 791; f90: 758; asm: 258; java: 31; sed: 1
file content (54 lines) | stat: -rw-r--r-- 1,126 bytes parent folder | download | duplicates (5)
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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#ifdef _WIN32 /* for sleep function */

#include <windows.h>

void mysleep(int sec) {
    Sleep((DWORD)sec * 1000);
}

#else /* Unix/POSIX */

#include <unistd.h>

void mysleep(int sec) {
    /* could use nanosleep, but on Solaris it needs -lrt  */
    sleep(sec);
}
#endif

int main(int argc, char* argv[])
{
    int status = 0;
    char line[1000];

    printf("stdout 1\n"); fflush(stdout);
    fprintf(stderr, "stderr 1\n");
    fflush(stderr);

    if (argc > 1 && strcmp(argv[1], "1") == 0) {
	while(fgets(line, 1000, stdin)) printf("stdin: %s", line);
	fflush(stdout);
    }
    if (argc > 1 && strcmp(argv[1], "1")) {
	status = atoi(argv[1]);
    }
    if (argc > 1 && strcmp(argv[1], "infinite_loop") == 0) {
	printf("Going to infinite loop...\n");
	fflush(stdout);
	while(1); /* infinite loop */
    }
    if (argc > 2 && strcmp(argv[1], "sleep") == 0) {
	int sec = atoi(argv[2]);
	printf("Sleeping for %d seconds...\n", sec);
	fflush(stdout);
	mysleep(sec);
	printf("Done sleeping for %d seconds.\n", sec);
	fflush(stdout);
    }
    
    exit(status);
}