-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintstatus.c
54 lines (48 loc) · 1018 Bytes
/
printstatus.c
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 <unistd.h>
#include "printstatus.h"
// prints information of process' status
void
print_status_info(struct cmd *cmd)
{
const char *action;
if (strlen(cmd->scmd) == 0 || cmd->type == PIPE)
return;
if (WIFEXITED(status)) {
action = "exited";
status = WEXITSTATUS(status);
} else if (WIFSIGNALED(status)) {
action = "killed";
status = -WTERMSIG(status);
} else if (WTERMSIG(status)) {
action = "stopped";
status = -WSTOPSIG(status);
} else {
return;
}
#ifndef SHELL_NO_INTERACTIVE
if (isatty(1)) {
fprintf(stdout,
"%s Program: [%s] %s, status: %d %s\n",
COLOR_BLUE,
cmd->scmd,
action,
status,
COLOR_RESET);
}
#else
MARK_UNUSED(action);
MARK_UNUSED(cmd);
#endif
}
// prints info when a background process is spawned
void
print_back_info(struct cmd *back)
{
#ifndef SHELL_NO_INTERACTIVE
if (isatty(1)) {
fprintf(stdout, "%s [PID=%d] %s\n", COLOR_BLUE, back->pid, COLOR_RESET);
}
#else
MARK_UNUSED(back);
#endif
}