M
M Herriott
Hello to all -
#1: I would have rather used an AND with the choice of newsgroups. I
would like to talk to those who subscribe to comp.lang.c++ AND
comp.unix.solaris - but I'm stuck with OR. Please accept my sincerest
apologies for what I am about to do, I know it is, in the purest sense,
incorrect.
Having said that much, let me describe my problem. I am running two
processes on a Solaris server. Process 1 forks and calls process 2 using
execv(). All well and good. The problem comes in when I try and pull the
passed args from the pointer array - I get nonsense where once there
was sense.
Now, I am full willing to admit I'm not sure what exactly I am doing
here. I believe my pointers have gotten fouled up, and I've been staring
at them for so long that they have ceased to mean anything. Please advise:
// Process 1
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>
#include <iostream.h>
void main()
{
int forkA, proc_id00, sleep_err, kill_err;
int time = 3;
int kill_sig = 9;
char *argv[3];
argv[0] = "one";
argv[1] = "two";
argv[2] = NULL;
forkA = fork ();
if (forkA == 0)
{
int error = 0;
int halftime = 5;
error = execv ("testit2", argv);
sleep_err = sleep(halftime);
exit (101);
}
else
{
sleep_err = sleep(time);
kill_err = kill (forkA, kill_sig);
exit (100);
}
}
// Process 2
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>
#include <iostream.h>
void main(int arg_count, char *arg_val)
{
char **argv = &arg_val;
int i = 0;
cout << "Program 2: ";
while (i < arg_count)
{
cout << argv[i++];
}
cout << endl;
exit(103);
}
My output looks like this: Program 2: ÿ¾ñÿ¾ñ(null)
#1: I would have rather used an AND with the choice of newsgroups. I
would like to talk to those who subscribe to comp.lang.c++ AND
comp.unix.solaris - but I'm stuck with OR. Please accept my sincerest
apologies for what I am about to do, I know it is, in the purest sense,
incorrect.
Having said that much, let me describe my problem. I am running two
processes on a Solaris server. Process 1 forks and calls process 2 using
execv(). All well and good. The problem comes in when I try and pull the
passed args from the pointer array - I get nonsense where once there
was sense.
Now, I am full willing to admit I'm not sure what exactly I am doing
here. I believe my pointers have gotten fouled up, and I've been staring
at them for so long that they have ceased to mean anything. Please advise:
// Process 1
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>
#include <iostream.h>
void main()
{
int forkA, proc_id00, sleep_err, kill_err;
int time = 3;
int kill_sig = 9;
char *argv[3];
argv[0] = "one";
argv[1] = "two";
argv[2] = NULL;
forkA = fork ();
if (forkA == 0)
{
int error = 0;
int halftime = 5;
error = execv ("testit2", argv);
sleep_err = sleep(halftime);
exit (101);
}
else
{
sleep_err = sleep(time);
kill_err = kill (forkA, kill_sig);
exit (100);
}
}
// Process 2
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>
#include <iostream.h>
void main(int arg_count, char *arg_val)
{
char **argv = &arg_val;
int i = 0;
cout << "Program 2: ";
while (i < arg_count)
{
cout << argv[i++];
}
cout << endl;
exit(103);
}
My output looks like this: Program 2: ÿ¾ñÿ¾ñ(null)