R
Renn25
Mitglied
Hallo!
Mal wieder ein Problem. Ich poste gleich ma den Quellcode hier.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <iostream>
using namespace std;
// globale Variablen
int i = 10;
int status;
char x;
//int terminated;
int main ()
{
// lokale Variablen
pid_t pid;
cout <<"Beispiel zum Aufruf von fork()" <<endl;
// einen neuen Prozess erzeugen
pid = fork ();
cout <<"\nKind-PID= " <<getpid() <<" Eltern-PID= " <<getppid();
cout <<"\n";
switch (pid)
{
// Fehlerfall
case -1:
fprintf (stderr, "Fehler beim Aufruf von fork().\n");
exit(0);
// Kindprozess
case 0:
cout <<"Child-Prozess startet eine Shell." <<endl;
execl("/bin/bash" , "Shell" , x,NULL);
exit(1);
// Vaterprozess bzw. pid > 0
default:
pid=wait(&status);
if(WIFEXITED(status))
{ cout <<"\nChild normal beendet...\n";
cout <<"Exit-Code: " <<WEXITSTATUS(status) <<endl;
}
else if (WIFSIGNALED(status))
{ cout <<"\nChild beendet über ein Signal...\n";
cout <<"Signalnummer: " <<WTERMSIG(status) <<endl;
}
exit(2);
}
}
Das Problem ist, der Child-Prozess soll eine Shell aufrufen (macht er auch laut Prozesstabelle), nur leider läst diese sich nicht über die PID killen. Ich kann die gestartete Shell nur über "exit" wieder verlassen bzw. wenn ich den Parant kille. Woran könnte das liegen?
Schonma Danke für eure Mühe!!
gruss
Renn
Mal wieder ein Problem. Ich poste gleich ma den Quellcode hier.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <iostream>
using namespace std;
// globale Variablen
int i = 10;
int status;
char x;
//int terminated;
int main ()
{
// lokale Variablen
pid_t pid;
cout <<"Beispiel zum Aufruf von fork()" <<endl;
// einen neuen Prozess erzeugen
pid = fork ();
cout <<"\nKind-PID= " <<getpid() <<" Eltern-PID= " <<getppid();
cout <<"\n";
switch (pid)
{
// Fehlerfall
case -1:
fprintf (stderr, "Fehler beim Aufruf von fork().\n");
exit(0);
// Kindprozess
case 0:
cout <<"Child-Prozess startet eine Shell." <<endl;
execl("/bin/bash" , "Shell" , x,NULL);
exit(1);
// Vaterprozess bzw. pid > 0
default:
pid=wait(&status);
if(WIFEXITED(status))
{ cout <<"\nChild normal beendet...\n";
cout <<"Exit-Code: " <<WEXITSTATUS(status) <<endl;
}
else if (WIFSIGNALED(status))
{ cout <<"\nChild beendet über ein Signal...\n";
cout <<"Signalnummer: " <<WTERMSIG(status) <<endl;
}
exit(2);
}
}
Das Problem ist, der Child-Prozess soll eine Shell aufrufen (macht er auch laut Prozesstabelle), nur leider läst diese sich nicht über die PID killen. Ich kann die gestartete Shell nur über "exit" wieder verlassen bzw. wenn ich den Parant kille. Woran könnte das liegen?
Schonma Danke für eure Mühe!!
gruss
Renn