from subprocess import call with open('test_seg.c', 'w') as f: f.write(""" struct test { long i; }; struct test* testArr[32000]; long i; int main(){ i = 0; ) """) for i in range(1, 900000): f.write(""" { struct test *t = malloc(sizeof(struct test)); i++; t->i = i; testArr[i] = t; free(t); } """) f.write("}") with open('test_noseg.c', 'w') as f: f.write(""" struct test { long i; }; struct test* testArr[32000]; long i; int main(){ i = 0; ) """) for i in range(1, 900000): f.write(""" { struct test *t = malloc(sizeof(struct test)); i++; t->i = i; testArr[i] = t; free(t); } """) f.write("}")