File: test6.15.prog.c

package info (click to toggle)
slurm-wlm 22.05.8-4%2Bdeb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 48,492 kB
  • sloc: ansic: 475,246; exp: 69,020; sh: 8,862; javascript: 6,528; python: 6,444; makefile: 4,185; perl: 4,069; pascal: 131
file content (60 lines) | stat: -rw-r--r-- 893 bytes parent folder | download | duplicates (7)
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
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <stdbool.h>

volatile bool  finish = false;
volatile bool  step   = false;

pid_t pid;

void sig_handler(int signo)
{
	if (pid)
		if (step)
			printf("Signaled: parent_step\n");
		else
			printf("Signaled: parent_command\n");
	else
		if (step)
			printf("Signaled: child_step\n");
		else
			printf("Signaled: child_command\n");
	finish = true;
}

int main(int argc, char *argv[])
{
	int i=0;

	if (argc>1)
		step = true;

	signal(SIGUSR1, sig_handler);

	pid = fork();

	if (pid)
		if (step)
			printf("Started: parent_step\n");
		else
			printf("Started: parent_command\n");
	else
		if (step)
			printf("Started: child_step\n");
		else
			printf("Started: child_command\n");

	while (!finish && i<10) {
		fflush(stdout);
		sleep(1);
		i++;
	}

	if (pid)
		wait(NULL);

	return 0;
}