OS: ubuntu 11.10 Webserver: Apache Code: PHP

Hello I'm attempting to "professional" a C code through PHP web site. After I run exactly the same C code on terminal, it really works fine, however when I "professional" it through PHP, I recieve a segmentation fault.

Any idea why such behavior? My C code does small "malloc"s in a couple of places. The code never the less works fine on directly performing through terminal using ./a.out

It is possible to way that i can gdb the C code, when PHP attempts to carry it out?


Probably it's a user permissions error. Your internet server will run like a different user (nobody, wwwrun or similar). Try doing an su to the net server user, and running the C program as that user.

What you might do is enabling core dump file creation and browse the core dump into gdb following the exe crash. Make it possible for core dump creation see what 'ulimit' does.

BTW: One possible reason behind your program crash could be uninitialized variables, particularly pointer variables.

Difficult to tell without really seeing the code. Are you certain your program does not leak? Is it possible to then add debug console output to determine when/where it crashes? Does your program attempt to access any ressources (like files, ports, etc.)? Exist sufficient privileges for that web server's user (or whomever runs the php script) to really carry it out correctly?