LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-01-2004, 03:37 AM   #1
ej25
Member
 
Registered: Nov 2004
Posts: 39

Rep: Reputation: 15
build a shell


Code:
 
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>

 

main (int argc, char *argv[] ){

	int i;
	int status;
	int c=1;
    int  forkresult ;
   
    forkresult = fork ( ) ;

     if (forkresult != 0)

            wait(&status);  
     

       else    
                          
            execvp (argv[1],&argv[1] );

              
      printf ("EXEC Failed\n") ;   
            
         exit(1);

}
I wrote this code which take as argment a command from the user and exexuit it

how can I make it loop for infinity and take each time a coomand from the user and how can I make it wait untiul the programme exits befor it print the promot again to recive the second coomand?
 
Old 12-01-2004, 03:49 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
shouldn't it be:
Code:
wait (forkresult)
status is a non initialised variable.

billy
 
Old 12-01-2004, 04:43 AM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
shouldn't it be:
code:
wait (forkresult)
status is a non initialised variable.
wait(&status) is right, no need to initialize status as the call purpose is precisely to affect it.

Quote:
how can I make it loop for infinity and take each time a coomand from the user
Something like:
Code:
while(1)
{
printf(prompt);
command=fgets(buffer,SIZE,stdin);
...
fork stuff
...
}
Quote:
and how can I make it wait untiul the programme exits befor it print the promot again to recive the second coomand?
the wait call should be enough
 
Old 12-02-2004, 07:01 AM   #4
DaZjorz
LQ Newbie
 
Registered: Nov 2004
Distribution: SuSE, LMC
Posts: 23

Rep: Reputation: 15
Cool, make your own shell... Heh Is the bash-shell a big program? I mean, if the shell that this guy made is as good as that one then it would be nice heh cuz that makes it very small and easy-to-compile

Are you going to build in some build-in programs?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
'sh' shell - Actually calls legacy Bourne shell, or uses system default? Dtsazza Linux - Software 1 10-28-2005 09:20 AM
running applications from one Linux build in another Linux build bcottam Linux - Distributions 2 04-13-2004 12:08 AM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 03:00 PM
Kazaa lite 2.0 build 2 and 2.02 build 5 walterw Linux - General 1 02-04-2003 04:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration