Without knowing anything much about your program - if it works normally when ran in one context and misbehaves when it's ran in another context - one possibility is it could be permissions related.
So for example - when it is attempting to perform an action, is it possible that the permissions of any files, or directories it uses are causing problems? e.g. preventing it from reading to/from a file/directory?
What level of privilege does the process run at when it fails? Is it running as root, or as a system user?
Also - have you tried using a debugger like gdb?
gdb can attach to a running process.
So you could try doing the following:
1. Build a debug version of your program, using the -g flag to generate debug information.
2. Launch the debug build of the program using whatever method is causing the programs execution to become problematic.
3. Launch gdb
4. Attach gdb to the PID of the running process using the following gdb command:
Where {PID} is the numeric Process ID of the running executable.
5. Load the symbol table, by loading the actual executable itself:
Code:
symbol-file /path/to/debug-executable
Where /path/to/debug-executable is the path to the executable with the debug information.
6. Now set some breakpoints near the problematic areas of the program.
7. Make a client connection to your program (from another terminal, or another PC) and then wait to see where/if gdb bombs out anywhere.
Once GDB has broken out at a breakpoint - you can examine the state of the variables in your program and step through the problematic areas to see what's happening.
Otherwise, if that does not work (or you aren't au-fait enough with gdb) - the only other option would be to put some additional checks in your code. There may be some problems that you aren't checking for in your code? Or perhaps you'll need to put some logging functionality in there, so you can see what happens when your program is running.
gdb will probably be your best bet. It has a bit of a learning curve, if you are new to it. But it is worth investing some time in learning to use it.