Skip to content

Commit

Permalink
[Add] README and some pinfo fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gsc2001 committed Sep 10, 2020
1 parent f768782 commit 7fd5670
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions src/pinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7fd5670

Please sign in to comment.