zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sabyasachi Ruj <ruj.sa...@gmail.com>
Subject Strange behavior if I am declaring a struct String_vector variable
Date Thu, 10 Mar 2011 13:17:54 GMT
I have two programs "trysample.cpp" and "sample.cpp". trysample.cpp
calls execv to invoke "sample", that is, compiled output of "sample.cpp".

sample.cpp simply prints the command line arguments passed to it.

The strange thing is if I am declaring a "struct String_vector"
variable in "trysample.cpp", the arguments received by sample.cpp
becomes wrong. If I am passing 3 arguments, it is showing us 5
arguments have been passed. But if I just comment the "struct
String_vector s;" part, it works fine!

Any idea?

I am giving code for both programs:

sample.cpp
=========
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>

int main(int argc, char *argv[])
{
  printf ("Number of arugments received: %d\n", argc);
  for (int i = 0; i < argc; i++) {
    printf("%s\n", argv[i]);
  }
}


trysample.cpp
=========
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include "zookeeper.h"


int main(int argc, char *argv[])
{
  struct String_vector s;
  int pid = fork();
  if (pid == 0) {
    char * argv[] =
{"/var/www/vhosts/apps.w/subdomains/sr.c/httpdocs/c/zookeeper/tests/sample",
"aaa", "ddd"};
    execv("/var/www/vhosts/apps.w/subdomains/sr.c/httpdocs/c/zookeeper/tests/sample",
argv);
    printf("returned error! %d\n", errno);
  }
}




--
Sabyasachi

Mime
View raw message