diff --git a/README.md b/README.md index ec21803..5aa14f5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,64 @@ # gSH A basic C shell + +## Project Structure + +The project contains the following folder with files described: + +- **build**: stores the build files +- **include**: stores all header files +- **src**: stores `.c` source code files + +## Instructions + +- ### Building + + To build normally + + ```bash + make + ``` + + To build with debugging on + + ``` + make debug + ``` + + ``` + NOTE: All the build files will be in the build folder + ``` + +- ### Running + + ```bash + ./gSH + ``` + +- ### Cleanup + + ```bash + make clean + ``` + +## File Contents + +- `globals.h`: File with global variable, structs and header files declarations. + +The following files are in `src` directory. The corresponding `.h` files can be found in `include` directory. `.h` files also contain brief description. + +- `main.c`: File with `main()` .Calls init ,repl and destroy functions. (This file does not has a corresponding `.h` file) +- `parse.c`: File with functions to take raw input string and parse it. Stores `;` seperated commands in `Command` struct and collection of all commands in input string in `ParsedCommands` struct +- `shell.c`: File with init, repl, byebye function. This also has function to execute `ParsedCommands` using corresponding executor +- `prompt.c`: File with function to return prompt string. +- `cd.c`: File with cd command implementation and executor +- `echo.c`: File with echo command implementation and executor +- `ls.c`: File with ls command implementation and executor +- `mpwd.c`: File with pwd command implementation and executor +- `pinfo.c`: File with pinfo command implementation and executor +- `errorHandler.c`: File with error handlers for syscalls +- `history.c`: File with history command implementation and executor. This file also contains functions to add a command to history, save history and load history +- `sysCommand.c`: File with function for execution of non-builtin commands in foreground or background +- `signalHandlers.c`: File with signal handlers. For now handler only for `SIGCHLD` signal +- `utils.c`: File with some utility functions diff --git a/src/pinfo.c b/src/pinfo.c index 6837ebd..2ea8408 100644 --- a/src/pinfo.c +++ b/src/pinfo.c @@ -16,7 +16,6 @@ void pinfoExec(Command c) void pinfo(char *pid) { - printf("hii"); char *procDir = (char *)malloc(MAX_LEN); sprintf(procDir, "/proc/%s", pid); @@ -58,13 +57,15 @@ void pinfo(char *pid) } i++; } + if (getpgid(atoi(pid_)) == tcgetpgrp(0)) + strcat(state, "+"); char *executableFile = (char *)malloc(MAX_LEN); sprintf(executableFile, "%s/exe", procDir); char *exec = (char *)malloc(MAX_LEN); int sz = handleSyscallint(readlink(executableFile, exec, MAX_LEN - 1), "reading exectuble link"); exec[sz] = '\0'; - + exec = replaceHomeDir(exec); // output printf("pid -- %s\n", pid_); printf("Process Status -- %s\n", state);