子进程在waitpid()之前结束

时间:2019-03-25 17:11:20

标签: c linux waitpid

我正在尝试使用waitpid()“冻结”父进程,直到子进程完成,但是我从-1函数中得到了waitpid()
我认为这是因为孩子在父母到达waitpid()之前就完成了。
您知道我该如何解决吗?我不在乎孩子的返回值。
谢谢!
代码:

  if((subProc = fork()) == -1) {
            printErrorMsg();
        }
        //exec the command in the sub process
        if (subProc == 0){
           //somethine...
}
        else {
          if (waitpid(subProc, NULL, 0) == -1 {
               _exit(1);
            }
        }

1 个答案:

答案 0 :(得分:-2)

感谢您的帮助,我编辑代码:

Sub CallMask()
    Masks "Hello", "XYZ"
End Sub

Sub Masks(sMask_I As String, sNoReplace_I As String)
    Dim matches As Collection, c

    Set matches = FindAll(Sheets("Sheet1").Columns(1), sMask_I)

    For Each c In matches
        If c.Offset(0, 1) <> sNoReplace_I Then
            c.Value = Replace(c.Value, sMask_I, c.Offset(0, 3).Value)
        End If
    Next c

End Sub

'return all matches as a collection
Public Function FindAll(rng As Range, val As String) As Collection
    Dim rv As New Collection, f As Range
    Dim addr As String

    Set f = rng.Find(what:=val, after:=rng.Cells(rng.Cells.Count), _
        LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, MatchCase:=False)
    If Not f Is Nothing Then addr = f.Address()

    Do Until f Is Nothing
        rv.Add f
        Set f = rng.FindNext(after:=f)
        If f.Address() = addr Then Exit Do
    Loop

    Set FindAll = rv
End Function

效果很好:)