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 8743603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:42:29+00:00 2026-06-13T11:42:29+00:00

So for an assignment we’re required to build a shell that, among other things,

  • 0

So for an assignment we’re required to build a shell that, among other things, emulates the & command line operator.

I’ve got the forking/exec-ing down, the issue is that calling waitpid with WNOHANG causes my program to hang after the execv has terminated. Once I hit enter the prompt comes back and the program works as normal. Note that this doesn’t occur with a blocking waitpid.

Here’s the pertinent code:

782   pid_t child = fork();  //Create child process
783   
784   char** charArgs = toCharMatrix(*args);
785   
786   //If creation failed, say so
787   if(child == -1) {
788     fprintf(stderr, "Error: Could not create child process.\n");
789     return -1;
790   } 
791   else if(child == 0) {  //else: child process code
792     
793     //If the given command can be executed, attempt to exectue it
794     if(access(charArgs[0], X_OK) == 0) 
795       execv(charArgs[0], charArgs); 
796     else { //Else tell the user that they are an idiot
797       fprintf(stderr, "%s is not a valid path.\n", charArgs[0]);
798       return -1;
799     } 
800     
801     _exit(0);
802   } 
803   else
804     waitpid(-1, NULL, WNOHANG);

I’ve tried a number of things in the last else statement (parent process code) from returns, to basically anything. Nothing seems to help. Once again, simply removing the WNOHANG option fixes the problem, but does not comply with the assignment specifications.

I also call waitpid(-1, NULL, WNOHANG); in the master loop right before the prompt is displayed to avoid any zombie children. This stupid carriage return issue is the only remaining problem. Thanks in advance.

  • 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-06-13T11:42:30+00:00Added an answer on June 13, 2026 at 11:42 am

    It’s very unlikely it actually hangs at waitpid. Try printing return code (and errno or strerror(errno)) of waitpid call. Your snippet does not show where it hangs. Most likely reason for program wanting a return press is, you call a function which reads stdin (or parent process does blocking wait, and child waits for return press).

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

Sidebar

Related Questions

So for a class assignment we're making our own basic shell. Among other functions,
My assignment requires that from be used as an argument for the command line
My assignment asks that: Create a directory ~/UnixCourse/scriptAsst . Turn the two-line version, above,
My assignment in Visual Basic 2010 is to build a order form that has
Got a homework assignment that is giving me problems.... Its modifying a JSF project
My assignment is to write a Unix shell script that asks the user for
My assignment is to write an overloaded version of iquote() , a method that
My assignment is to create a simple graph that has both Nodes and Edges.
My assignment requires that I have an ER diagram that shows the dependencies between
The assignment instructions are so: Write a method named evenSum that prompts the user

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.