How can a process be blocking another process (that it spawned)?

MarioDS

I have written a utility program that is used to start and stop a specific process. Now, in testing it, it somehow seems to be blocking the process that it spawns!

It uses named system events (see System.Threading.EventWaitHandle). After starting the process, it waits for the event to be set:

private static int StartRavenDB(string fileName, string workingDirectory, string arguments)
{
    var process = new Process
    {
        StartInfo =
        {
            FileName = fileName,
            WorkingDirectory = workingDirectory,
            Arguments = arguments,
            UseShellExecute = false,
            CreateNoWindow = true,
            RedirectStandardInput = true,
            RedirectStandardOutput = true
        }
    };

    process.Start();

    var eventWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset, "StartStopRavenDBUtility");
    eventWaitHandle.Reset();

    eventWaitHandle.WaitOne();

    process.StandardInput.WriteLine("q");
    process.WaitForExit();

    return process.ExitCode;
}

Now, the RavenDB process that starts is a web server listening on localhost:8080.

Shortly after starting that process using the above utility, the process does not respond to web requests. It keeps timing out. As soon as I kill the utility process, everything starts to work normal.

For the record, I'm 100% the EventWaitHandle is not set yet - the RavenDB process is there, but it doesn't behave as it should.

I don't know what is happening or why, it's a completely separate process. What causes this problem?

Micke

You should subscribe to the OutputDataReceived event or at least read the redirected standard output, to avoid blocking the thread. From the documentation:

These dependencies can cause deadlock conditions. When the caller reads from the redirected stream of a child process, it is dependent on the child. The caller waits for the read operation until the child writes to the stream or closes the stream. When the child process writes enough data to fill its redirected stream, it is dependent on the parent. The child process waits for the next write operation until the parent reads from the full stream or closes the stream. The deadlock condition results when the caller and child process wait for each other to complete an operation, and neither can continue. You can avoid deadlocks by evaluating dependencies between the caller and child process.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Killing a process spawned by another thread

From Dev

How can I identify the command that spawned a process listening on a certain port?

From Dev

Can't send anything to spawned Erlang process

From Dev

How to detect if a Node spawned process is still running?

From Dev

Interaction with spawned process in Scala

From Dev

How to detach from process, so that it can be traced by another process?

From Dev

With python multiprocessing how can child process terminate another child process?

From Dev

How can I track which process is calling another process (Linux)?

From Dev

Can't write to a spawned child_process's stdin on Windows

From Dev

Node.js can't get output of spawned process

From Dev

How do I get the pid of a spawned process using pexpect?

From Dev

How to wait on all child (and grandchild etc) process spawned by a script

From Dev

How to get the exit code of spawned process in expect shell script?

From Dev

How to replace node.js process with spawned child?

From Dev

How to get the output of a spawned child_process in Node.JS?

From Dev

How to get list of all child process spawned by a script

From Dev

How to wait on all child (and grandchild etc) process spawned by a script

From Dev

How do I get the pid of a spawned process using pexpect?

From Dev

How to monitor process spawned using launchUriAsync from WinJs

From Dev

Expect: How to get the exit code from spawned process

From Dev

Supervisord error "child process was not spawned"

From Dev

mount fails from spawned process

From Dev

killing the master process spawned by an at command

From Dev

How to Start Qt Event Process without blocking?

From Dev

How to Start Qt Event Process without blocking?

From Dev

How to show process state (blocking, non-blocking) in Linux

From Dev

How to trigger a process from another process in Linux?

From Dev

How can I find out what's blocking my device? (Sysinternals Process Explorer didn't help)

From Dev

How to switch from one process to another process and kill the first process

Related Related

  1. 1

    Killing a process spawned by another thread

  2. 2

    How can I identify the command that spawned a process listening on a certain port?

  3. 3

    Can't send anything to spawned Erlang process

  4. 4

    How to detect if a Node spawned process is still running?

  5. 5

    Interaction with spawned process in Scala

  6. 6

    How to detach from process, so that it can be traced by another process?

  7. 7

    With python multiprocessing how can child process terminate another child process?

  8. 8

    How can I track which process is calling another process (Linux)?

  9. 9

    Can't write to a spawned child_process's stdin on Windows

  10. 10

    Node.js can't get output of spawned process

  11. 11

    How do I get the pid of a spawned process using pexpect?

  12. 12

    How to wait on all child (and grandchild etc) process spawned by a script

  13. 13

    How to get the exit code of spawned process in expect shell script?

  14. 14

    How to replace node.js process with spawned child?

  15. 15

    How to get the output of a spawned child_process in Node.JS?

  16. 16

    How to get list of all child process spawned by a script

  17. 17

    How to wait on all child (and grandchild etc) process spawned by a script

  18. 18

    How do I get the pid of a spawned process using pexpect?

  19. 19

    How to monitor process spawned using launchUriAsync from WinJs

  20. 20

    Expect: How to get the exit code from spawned process

  21. 21

    Supervisord error "child process was not spawned"

  22. 22

    mount fails from spawned process

  23. 23

    killing the master process spawned by an at command

  24. 24

    How to Start Qt Event Process without blocking?

  25. 25

    How to Start Qt Event Process without blocking?

  26. 26

    How to show process state (blocking, non-blocking) in Linux

  27. 27

    How to trigger a process from another process in Linux?

  28. 28

    How can I find out what's blocking my device? (Sysinternals Process Explorer didn't help)

  29. 29

    How to switch from one process to another process and kill the first process

HotTag

Archive