等待定义时间的子进程

时间:2016-02-19 22:59:44

标签: c linux unix parent-child

我正在尝试通过做一些练习来学习在UNIX上编写C程序,但我一直坚持这个。在本练习中,我需要父进程等待子进程执行某些操作的确切时间,然后父进程应该通过提供子进程的ID来终止它。这是我的代码。

;directmedia=yes                ; Asterisk by default tries to redirect the
                                ; RTP media stream to go directly from
                                ; the caller to the callee.  Some devices do not
                                ; support this (especially if one of them is behind a NAT).
                                ; The default setting is YES. If you have all clients
                                ; behind a NAT, or for some other reason want Asterisk to
                                ; stay in the audio path, you may want to turn this off.

                                ; This setting also affect direct RTP
                                ; at call setup (a new feature in 1.4 - setting up the
                                ; call directly between the endpoints instead of sending
                                ; a re-INVITE).

                                ; Additionally this option does not disable all reINVITE operations.
                                ; It only controls Asterisk generating reINVITEs for the specific
                                ; purpose of setting up a direct media path. If a reINVITE is
                                ; needed to switch a media stream to inactive (when placed on
                                ; hold) or to T.38, it will still be done, regardless of this
                                ; setting. Note that direct T.38 is not supported.

;directmedia=nonat              ; An additional option is to allow media path redirection
                                ; (reinvite) but only when the peer where the media is being
                                ; sent is known to not be behind a NAT (as the RTP core can
                                ; determine it based on the apparent IP address the media
                                ; arrives from).

;directmedia=update             ; Yet a third option... use UPDATE for media path redirection,
                                ; instead of INVITE. This can be combined with 'nonat', as
                                ; 'directmedia=update,nonat'. It implies 'yes'.

;directmedia=outgoing           ; When sending directmedia reinvites, do not send an immediate
                                ; reinvite on an incoming call leg. This option is useful when
                                ; peered with another SIP user agent that is known to send
                                ; immediate direct media reinvites upon call establishment. Setting
                                ; the option in this situation helps to prevent potential glares.
                                ; Setting this option implies 'yes'.

问题如下。我不确定睡眠3是否表示父母等待3秒钟进行子进程。我想到了这样的方法,但似乎等待子进程终止。

;directrtpsetup=yes             ; Enable the new experimental direct RTP setup. This sets up
                                ; the call directly with media peer-2-peer without re-invites.
                                ; Will not work for video and cases where the callee sends
                                ; RTP payloads and fmtp headers in the 200 OK that does not match the
                                ; callers INVITE. This will also fail if directmedia is enabled when
                                ; the device is actually behind NAT.

第二个问题可能更简单,但我找不到哪个功能可以实现这个目标。子进程(或父进程,无关紧要)如何执行内置程序?

1 个答案:

答案 0 :(得分:0)

所以我很困惑,你究竟想做什么?要回答您的问题,要执行内置函数,您可以使用Foo(也可以使用system()函数族)(选中http://linux.die.net/man/3/system)。使用exec()wait()将等待(阻止)子进程终止,如果要向父进程指示内容,可以在子进程中使用waitpid()(类似于SIGCHLD)您可以让父母终止它。您还可以使用signal()让孩子在指定的时间后终止。