sh.c
static void init_shell() {

	char buf[BUFLEN] = {0};
	char* home = getenv("HOME");

	if (chdir(home) < 0) {
		snprintf(buf, sizeof buf, "cannot cd to %s ", home);
		perror(buf);
	} else {
		snprintf(promt, sizeof promt, "(%s)", home);
		setenv("PWD", home, 1);
		setenv("OLDPWD", home, 1);
	}
	
	// allocates space 
	// for the new handler´s stack
	ss.ss_sp = malloc(SIGSTKSZ);
	ss.ss_size = SIGSTKSZ;
	ss.ss_flags = 0;

	sigaltstack(&ss, NULL);
	
	// set signal handler for
	// SIGCHLD signal catching
	struct sigaction act;
	memset(&act, 0, sizeof(act));
	act.sa_handler = sig_handler;
	act.sa_flags = SA_ONSTACK;

	// blocks any other signal
	// interrupt when the handler
	// is being executed
	sigfillset(&act.sa_mask);
	
	sigaction(SIGCHLD, &act, NULL);
}
// initialize the shell
// with the "HOME" directory
initialize the shell
with the "HOME" directory
initialize the shell with the " HOME " directory
static void init_shell() {
	char buf[BUFLEN] = {0};
	char* home = getenv("HOME");
	if (chdir(home) < 0) {
		snprintf(buf, sizeof buf, "cannot cd to %s ", home);
		perror(buf);
	} else {
		snprintf(promt, sizeof promt, "(%s)", home);
		setenv("PWD", home, 1);
		setenv("OLDPWD", home, 1);
	}
	ss.ss_sp = malloc(SIGSTKSZ);
	ss.ss_size = SIGSTKSZ;
	ss.ss_flags = 0;
	sigaltstack(&ss, NULL);
	struct sigaction act;
	memset(&act, 0, sizeof(act));
	act.sa_handler = sig_handler;
	act.sa_flags = SA_ONSTACK;
	sigfillset(&act.sa_mask);
	sigaction(SIGCHLD, &act, NULL);
}
static void init_shell ( ) { char buf [ BUFLEN ] = { 0 } ; char * home = getenv ( " " ) ; if ( chdir ( home ) < 0 ) { snprintf ( buf , sizeof buf , " " , home ) ; perror ( buf ) ; } else { snprintf ( promt , sizeof promt , " " , home ) ; setenv ( " " , home , 1 ) ; setenv ( " " , home , 1 ) ; } ss . ss_sp = malloc ( SIGSTKSZ ) ; ss . ss_size = SIGSTKSZ ; ss . ss_flags = 0 ; sigaltstack ( & ss , NULL ) ; struct sigaction act ; memset ( & act , 0 , sizeof ( act ) ) ; act . sa_handler = sig_handler ; act . sa_flags = SA_ONSTACK ; sigfillset ( & act . sa_mask ) ; sigaction ( SIGCHLD , & act , NULL ) ; }
initialize the shell
with the "HOME" directory
initialize the shell with the " HOME " directory
// allocates space  // for the new handler´s stack // set signal handler for // SIGCHLD signal catching // blocks any other signal // interrupt when the handler // is being executed