Как выйти из дочернего процесса и возвратить его состояние из execvp ()?

вы можете установить этот пакет для включения отложенной загрузки в EF Core 2.1.

Microsoft.EntityFrameworkCore.Proxies

и затем установите этот конфиг в вашем ef dbContext

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
     => optionsBuilder
           .UseLazyLoadingProxies()
           .UseSqlServer("myConnectionString");

«Обратите внимание», этот пакет работает на EF Core 2.1.

17
задан duffymo 24 May 2009 в 14:26
поделиться

3 ответа

You need to use waitpid(3) or wait(1) in the parent code to wait for the child to exit and get the error message.

The syntax is:

pid_t waitpid(pid_t pid, int *status, int options);

or

pid_t wait(int *status);

status contains the exit status. Look at the man pages to see you how to parse it.


Note that you can't do this from the child process. Once you call execvp the child process dies (for all practical purposes) and is replaced by the exec'd process. The only way you can reach exit(0) there is if execvp itself fails, but then the failure isn't because the new program ended. It's because it never ran to begin with.

Edit: the child process doesn't really die. The PID and environment remain unchanged, but the entire code and data are replaced with the exec'd process. You can count on not returning to the original child process, unless exec fails.

17
ответ дан 30 November 2019 в 13:28
поделиться

From your question it's a little hard to figure out what you're asking. So I'll try to cover a couple of the related issues:

  • execvp() either does not return (on success), or it returns an error. Meaning your child code only need handle error conditions. Your child code should capture the result of execvp() and use that value in exit() as you suggested. Your child code should never return 0, since the only success means that the execvp worked and that processs will return 0 (or not).
  • The parent can obtain child info from waitpid() about it's exit status. There are several macros defined to pull info from the returned status parameter. Notable for your purpose are WIFEXITED to tell you if the child exited "normally", and WEXITSTATUS to get the child's status as passed to exit(). See the waitpid man page for other macros.
3
ответ дан 30 November 2019 в 13:28
поделиться

Используйте wait () или waitpid () в родительском процессе. Пример здесь: Код возврата, когда ОС завершает ваш процесс .

Кроме того, когда дочерний процесс умирает, сигнал SIGCHLD отправляется родительскому процессу.

3
ответ дан 30 November 2019 в 13:28
поделиться
Другие вопросы по тегам:

Похожие вопросы: