R
R
RainJa2015-05-11 19:34:19
linux
RainJa, 2015-05-11 19:34:19

How to protect a process from being interrupted on exit?

Good day!
I reformulated the question, because there was a lot of text: I'm doing a
lab. work on Unix - "process management" I run the
script:
$sh pr1

while((++i)); do echo $i » file.txt; sleep1; done

pr1 & put the process in the background
ps -l shows this process with TTY pts/5:
FS UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
1 S 11007 16359 16320 0 80 0 - 1735 - pts/5 00:00 :00 bash
Next, I reboot into the system (in theory, the process should die, right?), I enter ps -l
again , I see that there is no process 16359 , and I'm already connected with pts/7 (well, or from any other).
ps -u username - so the missing process is found, up and running from the old pts/5 TTY .
If I don't run any background processes, but just log into the system in a row, I connect all the time to the same TTY.
Actually, the question is:
According to the assignment, I have to "restart the system", see that I killed my background process with this, and then make interrupt protection for it (when I log out). Why doesn't the process die when I don't set nohup? Why am I being thrown to a new TTY? What am I doing wrong?)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
RainJa, 2015-05-16
@RainJa

C nohup figured it out. After checking the output of nohup.out , I saw a bunch of errors there.
Because when creating the procedure, extended syntax was used, sh does not know it, you need to add a link to bash at the beginning of the procedure text :
#!/bin/bash
while ((++i))
do
echo $i » file.txt
sleep 1
done

Well, if I just do pr1 &, then the process goes into the background, you can't kill it by logging out - except by killing the shell (probably :)) ... If you start with nohup, when you "re-login" PPID =1 (init), TTY = ?

S
Sergey Semenko, 2015-05-11
@abler98

If I understand you correctly, you can usescreen

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question