멈춘 프로세스를 끝난 것으로 치는 감독 규칙에 대해 질문을 받았는데, 작은 재현 하나면 문제가 바로 보여요.
셸 단계가 입력 파일을 쓰고, 그 뒤에 소비자가 예약돼 있어요. 쓰는 쪽이 중간에 일시 정지돼요. 감독자는 정지 이벤트를 보고, 제안된 규칙은 그걸 보고 소비자를 띄워요. 쓰는 쪽을 그냥 Bash로 적으면 이래요.
writer() {
for i in 1 2 3; do echo "row $i"; sleep 1; done > out.csv
}
writer &
pid=$!
sleep 1.5
kill -STOP "$pid"
ps -o stat= -p "$pid" # T
wc -l < out.csv # 2
kill -CONT "$pid"
wait "$pid"
wc -l < out.csv # 3
멈춰 있는 동안 ps는 T를 보여 주고, 파일에는 세 행 중 두 행만 있어요. 그 순간 시작한 소비자는 짧지만 멀쩡해 보이는 파일을 읽어요. 들어 있는 줄은 전부 온전하니까요. 파일 어디에도 뒤에 더 온다는 표시는 없어요. 쓰는 쪽을 재개하면 세 번째 행이 들어오는데, 소비자는 이미 두 행으로 일을 끝낸 뒤예요.
멈춘 건 끝난 게 아니에요. Bash에서 일시 정지된 작업은 jobs에 Stopped로 남아 있고, fg나 bg로 바로 다시 돌아가요. 출력을 검증한 것도 아직 없어요. 이 상태가 얼마나 갈지도 몰라요. 터미널에서 Ctrl-Z로 멈춘 작업은 누가 기억해 낼 때까지 그대로 있을 수 있어요.
이 규칙은 아마 상태를 실행 중과 실행 중 아님, 두 칸으로만 나누는 매핑에서 나왔을 거예요. 멈춘 작업은 실행 중이 아니니까 종료된 것과 같은 칸에 들어가고, 소비자가 떠요.
그래서 감독자는 소비자를 시작하기 전에 무엇을 요구해야 하고, 일시 정지된 동안 쓰는 쪽을 어떻게 보여 줘야 할까요? 대시보드에 세 번째 상태를 두고 싶은 마음이 있지만, 하나 제안하기 전에 다른 분들은 어디에 선을 긋는지 듣고 싶어요.
영어에서 번역·원문 보기Got a question about a supervisor rule that treats a stopped process as a finished one, and a tiny repro makes the problem obvious.
A shell step writes an input file and a consumer is scheduled after it. The writer gets suspended partway through. The supervisor sees a stopped event, and the proposed rule launches the consumer on that. Here's the writer side in plain Bash.
writer() {
for i in 1 2 3; do echo "row $i"; sleep 1; done > out.csv
}
writer &
pid=$!
sleep 1.5
kill -STOP "$pid"
ps -o stat= -p "$pid" # T
wc -l < out.csv # 2
kill -CONT "$pid"
wait "$pid"
wc -l < out.csv # 3
While it's stopped, ps shows T and the file has two of its three rows. A consumer started at that moment reads a short file that looks perfectly valid, since every line in it is complete. Nothing about the file says more is coming. Resume the writer and the third row lands after the consumer has already done its work on two.
Stopped isn't finished. In Bash a suspended job sits in jobs as Stopped, and fg or bg puts it right back to running. Nothing has validated the output yet either. The state can also last any amount of time. A job stopped from a terminal with Ctrl-Z can sit there until somebody remembers it.
The rule probably came from a status mapping with two buckets, running and not running. A stopped writer isn't running, so it lands in the same bucket as exited, and the consumer fires.
So what should the supervisor require before it starts the consumer, and how should it show the writer while it's suspended? My instinct is a third state on the dashboard, but I'd like to hear where others draw the line before I suggest one.