Problem
I would like to kill a process called raspivid (program which records videos using a Raspberry Pi Camera) but I cannot...
This is how I call it:
#!/bin/bash
#Start recording...
raspivid -w 800 -h 600 -t 15000 -o $1 -v -n -rot 270 >> /home/pi/log/camera_output.txt 2>&1 &
#Waiting the video to be complete
sleep 16
#Killing child process
sudo kill -9 $!
#Killing parent process
sudo kill -9 $$
If I search for this process, it is still there:
pi@raspberrypi ~ $ ps -ef | grep raspivid
root 7238 7234 0 21:53 ? 00:00:00 [raspivid]
pi 17096 14925 0 22:05 pts/0 00:00:00 grep --color=auto raspivid
If I try to kill it, it doesn't die. Instead it changes the parent PID to 1:
pi@raspberrypi ~ $ sudo killall raspivid
pi@raspberrypi ~ $ ps -ef | grep raspivid
root 7238 1 0 21:53 ? 00:00:00 [raspivid]
pi 17196 14925 0 22:05 pts/0 00:00:00 grep --color=auto raspivid
pi@raspberrypi ~ $ sudo killall raspivid
Observations:
- The call works fine for a while (2 hours or something) then it starts hanging.
- Only a physical power off solves the issue. I cannot reboot via terminal (it hangs too)
My questions:
- Why does Linux assign the parent PID to 1?
- Why the process cannot get killed? (I also tried
sudo kill -9 7238
)
EDIT:
aecolley was right. The column S shows D:
0 D 0 11823 11819 0 80 0 - 0 down ? 00:00:00 raspivid
top
how many zombies do you have or please provide which flags (STAT) this process has (if it hasZ
, it's zombie). E.g. byps wuax PID
. – kenorb Feb 04 '15 at 21:34(defunct)
suffix. But square braces give a clue - it may be a kernel thread – myaut Feb 04 '15 at 21:38ps
for zombies is actually<defunct>
(with angle brackets). – vinc17 Feb 04 '15 at 21:48cat /proc/7238/stack
. It will show what process is doing now. – myaut Feb 04 '15 at 21:51& sleep 16; kill $!
implements a 16-second timeout. What makes no sense, but doesn't hurt here, is callingsudo
and usingkill $$
rather thanexit
to terminate the shell script. – Gilles 'SO- stop being evil' Feb 04 '15 at 23:01