please can any one help me in my shell project
like this :

Develop a c program which serve as s shell interface that accepts user command and then executes each command in separate process. The shell interface provides a command prompt ( sh> ) after which next command is entered .

#define TRUE 1 

while(TRUE){ //repeat forever 
  type_prompt(); //display prompt on the screen 
  read_command (command, parameters); //read input from terminal 
  if(fork()!=0){ //fork off child process 
  waitpid(‐1, &status, 0); //wait for child to exit 
  execve(command, parameters, 0); //execute command 

Write a shell that is similar to the above code snippet, but contains enough code that it actually works so you can test it. You may also add some features such as redirection of in input and output, pipes, and background jobs.
If the user entered “& “ at the end of his/her command, then the process (command) will be executed in the background and the shell WILL Not WAIT It To Terminate.
You can experience background process yourself by trying the following command on bash shell.
> kwrite
The kwrite application will be run, and the shell prompt will not prompt a user until you terminate kwrite. On the contrary, if you tried the following command, the prompt will return to the user to accept other commands while kwrite (child process) is running in the background!

where is your code? No one here will write that program for you.

and this is my code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>

#define MAX_ARGS 10
#define MAX_LEN  100

void child(int argc, char *argv[MAX_ARGS]);

int main()
  int argc, n = 0;
  int status;
  char input[MAX_LEN], *argv[MAX_ARGS], *cp;
  const char *delim = " \t\n"; /* delimiters of commands */

  while (1) {
    /* show a prompt */
    printf("sh-> "); 

    /* read a line */
    if (fgets(input, sizeof(input), stdin) == NULL) {
      /* inputed EOF(Ctrl-D) */

    /* split the input to commands with blank and Tab */
    cp = input;
    for (argc = 0; argc < MAX_ARGS; argc++) {
      if ((argv[argc] = strtok(cp,delim)) == NULL)
      cp = NULL;
    /* exit this shell when "exit" is inputed */
    if(strcmp(argv[0], "exit") == 0) {
    pid_t pid = fork();
    if(pid == -1) {
 /* failed to fork() */
    } else if(pid == 0) {
 /* child process */
      child(argc, argv);
    } else {


void child(int argc, char *argv[MAX_ARGS]) {
  execvp(argv[0], argv);

the problem is i can not use pipe, process background..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.