Portál AbcLinuxu, 29. listopadu 2025 19:57
int main ()
{
int fds[2];
pid_t pid;
pid_t pid2;
pipe (fds);
pid = fork ();
if (pid == (pid_t) 0)
{
close (1);
dup (fds[1]);
execlp ("ls", "ls","-al","/usr/include", 0);
}
else
{
waitpid (pid, NULL, 0);
pid2=fork();
if (pid2 == (pid_t) 0)
{
close (0);
dup (fds[0]);
execlp ("more","more", 0);
}
else
{waitpid (pid2, NULL, 0);}
}
return 0;
}
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
int main ()
{
int fds[2];
pid_t pid;
pid_t pid2;
pipe (fds);
pid = fork ();
if (pid == (pid_t) 0)
{
close (1);
dup (fds[1]);
close (fds[0]);
close (fds[1]);
execlp ("ls", "ls","-al","/usr/include", 0);
}
else
{
pid2=fork();
if (pid2 == (pid_t) 0)
{
close (0);
dup (fds[0]);
close (fds[0]);
close (fds[1]);
execlp ("more","more", 0);
}
else
{
close (fds[0]);
close (fds[1]);
/* FIXME */
wait (NULL);
wait (NULL);
}
}
return 0;
}
+-, moc jsem to nezkoumal.
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.