Skip to content

Commit

Permalink
killing the child process when command don't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
celestecote21 committed Sep 19, 2020
1 parent 97579c8 commit 7aed234
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@ Module.symvers
Mkfile.old
dkms.conf



pretty_shell

.clangd
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ $(OBJ): $(SRC)
cd $(SRC_DIR) && $(MAKE)

clean:
rm $(NAME)
@(cd $(SRC_DIR) && $(MAKE) $@)
135 changes: 135 additions & 0 deletions Session.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
let SessionLoad = 1
if &cp | set nocp | endif
let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0
let v:this_session=expand("<sfile>:p")
silent only
silent tabonly
cd ~/docs/C/shell
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
let s:wipebuf = bufnr('%')
endif
set shortmess=aoO
argglobal
%argdel
$argadd src/color.c
$argadd src/exec.c
$argadd src/main.c
$argadd src/my_printf.c
$argadd src/parser.c
$argadd src/shell.c
$argadd include/color.h
$argadd include/exec.h
$argadd include/lib.h
$argadd include/my_printf.h
$argadd include/parser.h
$argadd include/shell.h
edit src/shell.c
set splitbelow splitright
wincmd _ | wincmd |
vsplit
1wincmd h
wincmd _ | wincmd |
split
1wincmd k
wincmd w
wincmd w
set nosplitbelow
set nosplitright
wincmd t
set winminheight=0
set winheight=1
set winminwidth=0
set winwidth=1
exe '1resize ' . ((&lines * 21 + 22) / 45)
exe 'vert 1resize ' . ((&columns * 117 + 117) / 234)
exe '2resize ' . ((&lines * 21 + 22) / 45)
exe 'vert 2resize ' . ((&columns * 117 + 117) / 234)
exe 'vert 3resize ' . ((&columns * 116 + 117) / 234)
argglobal
if bufexists("src/shell.c") | buffer src/shell.c | else | edit src/shell.c | endif
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let s:l = 29 - ((13 * winheight(0) + 10) / 21)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
29
normal! 017|
wincmd w
argglobal
if bufexists("src/parser.c") | buffer src/parser.c | else | edit src/parser.c | endif
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let s:l = 46 - ((0 * winheight(0) + 10) / 21)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
46
normal! 0
wincmd w
argglobal
if bufexists("src/exec.c") | buffer src/exec.c | else | edit src/exec.c | endif
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let s:l = 100 - ((42 * winheight(0) + 21) / 43)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
100
normal! 030|
wincmd w
3wincmd w
exe '1resize ' . ((&lines * 21 + 22) / 45)
exe 'vert 1resize ' . ((&columns * 117 + 117) / 234)
exe '2resize ' . ((&lines * 21 + 22) / 45)
exe 'vert 2resize ' . ((&columns * 117 + 117) / 234)
exe 'vert 3resize ' . ((&columns * 116 + 117) / 234)
tabnext 1
badd +21 src/color.c
badd +1 src/exec.c
badd +0 src/main.c
badd +0 src/my_printf.c
badd +1 src/parser.c
badd +64 src/shell.c
badd +0 include/color.h
badd +0 include/exec.h
badd +0 include/lib.h
badd +0 include/my_printf.h
badd +0 include/parser.h
badd +0 include/shell.h
if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0
silent exe 'bwipe ' . s:wipebuf
endif
unlet! s:wipebuf
set winheight=1 winwidth=20 shortmess=filnxtToOSc
set winminheight=1 winminwidth=1
let s:sx = expand("<sfile>:p:r")."x.vim"
if filereadable(s:sx)
exe "source " . fnameescape(s:sx)
endif
let &so = s:so_save | let &siso = s:siso_save
nohlsearch
doautoall SessionLoadPost
unlet SessionLoad
" vim: set ft=vim :
79 changes: 61 additions & 18 deletions compile_commands.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,62 @@
[
{
"directory": "/home/celeste/docs/C/shell/src",
"arguments": [
"gcc",
"-c",
"color.c",
"exec.c",
"main.c",
"my_printf.c",
"parser.c",
"shell.c",
"-L../libs/",
"-lmy",
"-I../include/"
],
"file": "shell.c"
}
]
{
"arguments": [
"gcc",
"-c",
"-I../include/",
"color.c"
],
"directory": "/home/celeste/docs/C/shell/src",
"file": "color.c"
},
{
"arguments": [
"gcc",
"-c",
"-I../include/",
"exec.c"
],
"directory": "/home/celeste/docs/C/shell/src",
"file": "exec.c"
},
{
"arguments": [
"gcc",
"-c",
"-I../include/",
"main.c"
],
"directory": "/home/celeste/docs/C/shell/src",
"file": "main.c"
},
{
"arguments": [
"gcc",
"-c",
"-I../include/",
"my_printf.c"
],
"directory": "/home/celeste/docs/C/shell/src",
"file": "my_printf.c"
},
{
"arguments": [
"gcc",
"-c",
"-I../include/",
"parser.c"
],
"directory": "/home/celeste/docs/C/shell/src",
"file": "parser.c"
},
{
"arguments": [
"gcc",
"-c",
"-I../include/",
"shell.c"
],
"directory": "/home/celeste/docs/C/shell/src",
"file": "shell.c"
}
]
Binary file modified pretty_shell
Binary file not shown.
5 changes: 5 additions & 0 deletions src/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,21 @@ int execute(char** argv){
int status;

switch(child_pid = fork()){
// error on the fork
case -1:
my_printf("error on fork");
exit(EXIT_FAILURE);
break;
// child process
case 0:
// my_printf("child processe");

execvp(argv[0], argv);
my_printf("the commande is not found\n");
// we exit the child process
exit(EXIT_SUCCESS);
break;
// parent process
default:
wait(&status);
}
Expand Down
2 changes: 2 additions & 0 deletions src/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ char my_getchar(void){
char* read_line(int* size_line){
char ch;
char* buff = malloc(BUFFER_SIZE);

int current_size = BUFFER_SIZE;
int position;
if(!buff){
Expand All @@ -71,5 +72,6 @@ char* read_line(int* size_line){
}
}
*size_line = position;
buff[position] = '\0'; // put the end caractere a the end of the string we get
return buff;
}

0 comments on commit 7aed234

Please sign in to comment.