#Shell mimic using c - Problem: Segmentation failed - exec(), fork(), and pipe() family

1 messages · Page 1 of 1 (latest)

shadow drift
#

I have got segmentation failed on my program. I have tried to create as many catch cases to find out wheres the problem and let the program successfully run. I am currently reexaminating my layers of loops to see if my programming logic is wrong (as cmdArgv will be messed up if thats wrong). I wonder if I am in the right direction of debugging, so I am asking someones help here.
Input: ls (as taken in line 65 fgets(input, 1024, stdin);)

Current output (in gdb):

(gdb) run
...
## JCshell [1086] ## ls
Program received signal SIGSEGV, Segmentation fault.
__execvpe (file=0x0, argv=0x7fffffffbc40, envp=0x7fffffffe1f8) at ./posix/execvpe.c:190
190     ./posix/execvpe.c: No such file or directory.

(gdb) print cmdArgv
No symbol "cmdArgv" in current context.

Expected output:

## JCshell [1086] ## ls // as in input 
shell_prog.c a.out // as in execvp
(PID)1087 (CMD)tloop (STATE)Z (EXCODE)2 (PPID)261 (USER)2.00 (SYS)0.00 (VCTX)13 (NVCTX)2 // some status as in printProcessDetails()

My code: as in attached

Sorry if I am not clear enough or using the wrong tag. please correct me if you notice i have done something wrong in the code or/and the posting format

sage sapphireBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

shadow drift
#

Update: still open but I have got some progress
I think it's because of printProcessDetails() / something is wrong about calling this function. But I am still working on why, but the program is running smoothly now as I commented those related lines.