Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6777893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:12:07+00:00 2026-05-26T16:12:07+00:00

I am creating a simple Unix shell in C. I use the fork() to

  • 0

I am creating a simple Unix shell in C. I use the fork() to clone the process and exec to execute a new one. It works fine when you are inputting data for the first time in the shell. But when it comes the second iteration fork returns -1.

e.g

…>ls -l /

/results here/

…>ls -l /

forking failed

here is a part of the code:

int execute(char path[80],char *args[]){
pid_t pid;
if((pid=fork())<0){
 printf("forking failed"); // The forking failed due to Cannot allocate memory error
 exit(0);
}else if(pid==0){
 execv(path,args);
}else{
 wait(NULL);
}
return 0
}

where path is “bin/ls” and args “ls”,NULL

the main is looks like

int main(){
 while(1){
 //read from keyboard
 //find the program path
 //fill args
 execute(path,args);
 }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:12:08+00:00Added an answer on May 26, 2026 at 4:12 pm

    Change your first if branch to this:

    if((pid=fork())<0){
     perror("forking failed");
     exit(0);
    }
    

    This will tell you what went wrong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I'm creating a simple Windows form, is it starting in a new thread
I'm creating a simple BizTalk 2010 process that will convert a 4010 835 file
I'm creating a simple WP7 app, to have all network settings in one place,
I am creating a simple Unix server written in C++ that simply waits for
Creating simple php login scripts is easy, with simple one table mysql integration. I
I'm creating a simple test application so I can see how ASP.Net MVC works
Creating some simple html pages specific for the iphone, and would like to use
I'm creating simple script to convert mp3 files using shell script. I decided to
As in the question Creating simple c++.net wrapper. Step-by-step I am tring to use
When creating a simple object hierarchy in Python, I'd like to be able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.