0

A small shell script writes to a terminal, in while-loop, with echo.

If I close the terminal, it re-attaches to the new terminal I start - usually /dev/pts/0 but it has also attached to /dev/pts/10.

It survives re-boot. I can't find what process it is:

ps -elf | awk '{if ($5 == 1){print $4" "$5" "$15}}'

shows no shells running apart from the terminal I am on, and the pts it is writing to. If I kill those, and start again, it continues to write, but I see no shell.

The script sleeps for a second. I've tried looking for sleep in ps, but it never seems to appear.

How can I find and kill it? I'm running Ubuntu 17.04 btw.

  • Do you know what it is? How do you know it's a "small shell script"? – Joe P Jun 11 '17 at 9:46
  • Can you provide any other details? – Ravexina Jun 11 '17 at 10:07
  • I wrote the script - it's a for loop, with a sleep 1, and a write to the terminal. I don't have the exact script, it's not in my history. I was trying to test something else, and got stuck with it as an orphan process. – Peter Brooks Jun 11 '17 at 12:27
  • 1
    AFAIK processes don't survive boot - so it's most likely something that's being run from one of your shell initialization scripts (~/.bashrc, ~/.bash_profile, ~/.profile` etc.) – steeldriver Jun 11 '17 at 12:34
  • Yes, it must be stored somewhere and invoked during boot. – Joe P Jun 11 '17 at 14:37
0

If it's writing to the terminal it must have (probably has) a handle to the terminal. In that case

lsof `tty`

from the terminal it's writing to should list it, giving you the pid.

(Or substitute the actual terminal e.g. lsof /dev/pts/0.)

| improve this answer | |
  • Thank you, a good approach. Unfortunately, it is spawning too quickly to do much about it. lsof gives the PID, but, before there's a chance to kill it, it's respawned with a new one. – Peter Brooks Jun 11 '17 at 9:57
  • Can you get the parent pid? – Joe P Jun 11 '17 at 10:13
  • Yes. Again, unfortunately, it only sees the shell itself - even with lsof -R /dev/pts/0 ` COMMAND PID PPID USER FD TYPE DEVICE SIZE/OFF NODE NAME bash 20451 20384 root 0u CHR 136,1 0t0 4 /dev/pts/1 bash 20451 20384 root 1u CHR 136,1 0t0 4 /dev/pts/1 bash 20451 20384 root 2u CHR 136,1 0t0 4 /dev/pts/1 bash 20451 20384 root 255u CHR 136,1 0t0 4 /dev/pts/1` – Peter Brooks Jun 11 '17 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.