模拟Ctrl + C按下/将'SIGINT'发送给子进程

时间:2019-06-03 20:13:46

标签: ruby shell concurrency fork

此代码有什么问题?我正在尝试向子进程发送SIGINT,以允许gst-launch-1.0在录制完成后正常退出:

@pid = fork {
  exec("gst-launch-1.0 -e v4l2src device=/dev/video0 ! videoconvert ! vaapih264enc rate-control=vbr bitrate=10000 quality-level=4 keyframe-period=30 num-slices=1 refs=1 max-bframes=2 ! queue ! mux. alsasrc ! audio/x-raw,width=16,depth=16,rate=44100,channel=1 ! audioconvert ! audioresample ! voaacenc ! aacparse ! queue ! mp4mux name=mux ! filesink location='/tmp/test-010.mp4' sync=false")
}
sleep 5
puts 'Killing child process and waiting...'
Process.kill 'INT', @pid
Process.wait

如您所见,我发出了Process.kill 'INT', @pid,据我所知,它应该与运行ctrl+c命令(或任何CLI命令)时按gst-launch-1.0相同。直接。

但是Ruby脚本的输出是:

Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Got context from element 'vaapiencodeh264-0': gst.vaapi.Display=context, gst.vaapi.Display=(GstVaapiDisplay)"\(GstVaapiDisplayGLX\)\ vaapidisplayglx0";
Setting pipeline to PLAYING ...
New clock: GstAudioSrcClock
Redistribute latency...
Killing child process and waiting...

该脚本刚刚挂起。基本上,看来Process.kill调用没有执行任何操作,或者至少信号没有到达子进程。我的代码有什么问题?

作为参考,当我确实直接从CLI运行gst-launch-1.0命令并过一会儿按ctrl+c时,会发生以下情况:

gst-launch-1.0 -e v4l2src device=/dev/video0 ! videoconvert ! vaapih264enc rate-control=vbr bitrate=10000 quality-level=4 keyframe-period=30 num-slices=1 refs=1 max-bframes=2 ! mp4mux name=mux ! filesink location=test-006.mp4 sync=false
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Got context from element 'vaapiencodeh264-0': gst.vaapi.Display=context, gst.vaapi.Display=(GstVaapiDisplay)"\(GstVaapiDisplayGLX\)\ vaapidisplayglx0";
Setting pipeline to PLAYING ...
New clock: GstSystemClock

捕获正在进行中。

准备结束捕获时,我按ctrl+c,输出如下:

^Chandling interrupt.
Interrupt: Stopping pipeline ...
EOS on shutdown enabled -- Forcing EOS on the pipeline
Waiting for EOS...
Got EOS from element "pipeline0".
EOS received - stopping pipeline...
Execution ended after 0:00:08.524849001
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

0 个答案:

没有答案