You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a subprocess outputs large amount of data, it deadlocks both parent and subprocess due to pipe blocking:
#include<stdlib.h>#include<stdio.h>#include"subprocess.h"intmain() {
constchar*command_line[] = {"dd", "if=/dev/zero", "bs=1k", "count=65", NULL};
structsubprocess_sprocess;
intresult=subprocess_create(command_line, subprocess_option_search_user_path, &process);
if (result) {
fprintf(stderr, "Failed to create subprocess: %d\n", result);
return1;
}
intproc_return;
result=subprocess_join(&process, &proc_return);
if (result) {
fprintf(stderr, "Failed to join subprocess\n");
return1;
}
printf("Subprocess returned %d\n", proc_return);
result=subprocess_destroy(&process);
if (result) {
fprintf(stderr, "Failed to join subprocess\n");
return1;
}
return0;
}
Notice that subprocess dd writes 65k data to stdout, which is greater than Linux's default pipe buffer size, thus blocking the child. However, since subprocess_read_stdout must be used after joining, the parent process cannot progress either, as it can neither drain the pipe nor wait for child to finish.
The text was updated successfully, but these errors were encountered:
I can't think of a better solution than to advise you use async. I don't really want to start spawning threads behind your back to handle this kind of thing (and don't know of another way to generally fix this!).
If a subprocess outputs large amount of data, it deadlocks both parent and subprocess due to pipe blocking:
Notice that subprocess
dd
writes 65k data to stdout, which is greater than Linux's default pipe buffer size, thus blocking the child. However, sincesubprocess_read_stdout
must be used after joining, the parent process cannot progress either, as it can neither drain the pipe nor wait for child to finish.The text was updated successfully, but these errors were encountered: