Discussion:
[Gc] child process goes to crash when the program invokes gtk_init
y***@toshiba.co.jp
2015-08-05 05:35:55 UTC
Permalink
I wrote a tiny test program as seen in the following:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <gtk/gtk.h>
#include <sys/wait.h>

#define GC_DEBUG
#include <gc.h>

char *copy (const char *str)
{
char *p = NULL;
if (!str) return NULL;
if ((p = GC_MALLOC_ATOMIC(strlen(str) + 1)))
(void) strcpy(p, str);
return(p);
}

int main(int argc, char** argv)
{
pid_t pid;
int status;
char *teststr = "This is a test string.";
char *c1, *c2;


c1 = copy(teststr);
printf ("adress:%p activesize:%d\n", c1, (int)GC_size(c1));

gtk_init(&argc, &argv);

pid = fork();
if (pid == 0) {
c2 = copy ("another test str");

printf ("adress:%p activesize:%d\n", c1, (int)GC_size(c1));
printf ("%s\n", c1);

_exit(0);
}
waitpid (pid, &status, 0);
if (WIFSIGNALED(status)){
fprintf(stderr, "child signal %d\n", WTERMSIG(status));
}
return (0);
}

This program is compiled at Cygwin(64, version 2.2.0) environment with gcc4.9.3. My Cygwin(64) environment is installed to windowns7. The CPU is Intel Core i7-4770 @ 3.4GHz.

However, this program causes SEGV in the child process.
$ ./a.exe
adress:0x600060fe0 activesize:64
child signal 11 <-- this means child process ended with SIGSEGV.

I confirmed SIGSEGV is raised at
c2 = copy ("another test str");
that invokes GC_MALLOC_ATOMIC.
But, if gtk_init() is commented out, or if GC_DEBUG is not defined, this program seems to be ended successfully.
$ ./a.exe
adress:0x600060fe0 activesize:32
adress:0x600060fe0 activesize:32 <-- output from child process
This is a test string. <-- output from child process

gtk is gtk+-2.24.28.
I have fears in using boehm-gc together with gtk+-2.0. Does anyone give me comments/advices ?
Thanks in advance.
Yoichi Niitsu
Kjetil Matheussen
2015-08-05 16:11:14 UTC
Permalink
Post by y***@toshiba.co.jp
gtk is gtk+-2.24.28.
I have fears in using boehm-gc together with gtk+-2.0. Does anyone give me
comments/advices ?
Thanks in advance.
Hi,

I've used gtk with boehm-gc in a quite large program before without
problems, but not in cygwin, only mingw/osx/linux.
And I didn't fork either. I don't know how forking works in cygwin (think I
remember reading something about fork
being impossible to emulate in Windows, but maybe that is not true
anymore), and I also don't know if there
is anything (in general) to look out for when forking in a bdwgc program.

But maybe your program works if you just call GC_INIT() right after main?
Ivan Maidanski
2015-08-05 21:55:14 UTC
Permalink
Hi,

And call GC_set_handle_fork(1) before GC_INIT().

I assume you use bdwgc master
Post by y***@toshiba.co.jp
gtk is gtk+-2.24.28.
I have fears in using boehm-gc together with gtk+-2.0. Does anyone give me comments/advices ?
Thanks in advance.
Hi,
I've used gtk with boehm-gc in a quite large program before without problems, but not in cygwin, only mingw/osx/linux.
And I didn't fork either. I don't know how forking works in cygwin (think I remember reading something about fork
being impossible to emulate in Windows, but maybe that is not true anymore), and I also don't know if there
is anything (in general) to look out for when forking in a bdwgc program.
But maybe your program works if you just call GC_INIT() right after main?
_______________________________________________
bdwgc mailing list
https://lists.opendylan.org/mailman/listinfo/bdwgc
y***@toshiba.co.jp
2015-08-06 01:00:14 UTC
Permalink
Dear Mr. Maidanski and Mr. Matheussen,
Thanks a lot for your response. I'm sorry that I forgot to call GC_INIT at very beginning of the program.
I inserted them into and tested again the next program:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <gtk/gtk.h>
#include <sys/wait.h>

#define GC_DEBUG
#include <gc.h>

char *
copy (const char *str)
{
char *p = NULL;
if (!str) return NULL;
if ((p = GC_MALLOC_ATOMIC(strlen(str) + 1)))
(void) strcpy(p, str);
return(p);
}


int main(int argc, char** argv)
{
pid_t pid;
int status;
char *teststr = "This is a test string.";
char *c1, *c2;

GC_set_handle_fork(1);
GC_INIT();

c1 = copy(teststr);
printf ("adress:%p activesize:%d\n", c1, (int)GC_size(c1));

gtk_init(&argc, &argv);

pid = fork();
if (pid == 0) {
c2 = copy ("another test str");

printf ("adress:%p activesize:%d\n", c1, (int)GC_size(c1));
printf ("%s\n", c1);

_exit(0);
}
waitpid (pid, &status, 0);
if (WIFSIGNALED(status)){
fprintf(stderr, "child signal %d\n", WTERMSIG(status));
}
return (0);
}

The result becomes perfect!
$ ./a.exe
adress:0x600060fe0 activesize:64
adress:0x600060fe0 activesize:64
This is a test string.

I greatly appriciate your helps!

Sincerely yours,
Yoichi Niitsu

From: Ivan Maidanski [mailto:***@mail.ru]
Sent: Thursday, August 06, 2015 6:55 AM
To: ***@notam02.no
Cc: ***@lists.opendylan.org; niitsu yoichi(新津 陽一郎 ○MSジ□MS設○AI設)
Subject: Re[2]: [Gc] child process goes to crash when the program invokes gtk_init

Hi,

And call GC_set_handle_fork(1) before GC_INIT().

I assume you use bdwgc master

Среда, 5 августа 2015, 18:11 +02:00 от Kjetil Matheussen <***@gmail.com>:

gtk is gtk+-2.24.28.
I have fears in using boehm-gc together with gtk+-2.0. Does anyone give me comments/advices ?
Thanks in advance.

Hi,

I've used gtk with boehm-gc in a quite large program before without problems, but not in cygwin, only mingw/osx/linux.
And I didn't fork either. I don't know how forking works in cygwin (think I remember reading something about fork
being impossible to emulate in Windows, but maybe that is not true anymore), and I also don't know if there
is anything (in general) to look out for when forking in a bdwgc program.

But maybe your program works if you just call GC_INIT() right after main?


_______________________________________________
bdwgc mailing list
***@lists.opendylan.org
https://lists.opendylan.org/mailman/listinfo/bdwgc

Loading...