hope you understand my english correct, it isnt that good, with switch i mean i want to tell the child to sleep so the parent is working, like in
Code:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
int main (){
int pid, j, i;
int pfds[2];
pipe(pfds);
char buf[30];
int once = 0;
pid = fork();
if (pid == 0)
{
/* Kindprozess
* wenn fork eine 0 zurückgibt, befinden wir uns im Kindprozess
*/
for (j=0; j < 10; j++)
{
printf ("Kindprozess: %d (PID: %d)\n", j, getpid());
write(pfds[1], "test", 5);
sleep (1);
}
exit (0);
}
else if (pid > 0)
{
/* Vaterprozess
* Gibt fork einen Wert größer 0 zurück, so ist dies die PID des Kindprozesses
*/
for (i=0; i < 10; i++)
{
printf ("Vaterprozess: %d (PID: %d)\n", i, getpid());
read(pfds[0], buf, 5);
printf("PARENT: read \"%s\"\n", buf);
sleep (1);
}
}
else
{
/* Wird ein negativer Wert zurückgegeben, ist ein Fehler aufgetreten */
fprintf (stderr, "Error");
exit (1);
}
return 0;
}
but with an running shell in the child
so i cant tell the shell to sleep to"switch"
so is there no way to do that without making a second programm ?