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

  • Home
  • SEARCH
  • 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 3220620
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:46:57+00:00 2026-05-17T15:46:57+00:00

int handleCommand(char *command) { pid_t pid; pid = fork(); if (pid > 0) {

  • 0
int handleCommand(char *command) {
    pid_t pid;
    pid = fork();

    if (pid > 0) {
        sleep(0.5);
    } else if (pid == 0) {
        execCommand(command);
        //strcat(path[0], command);
        //printf("%s", path[0]);
        //execve(path[0], path, NULL);
        //printf("\n");
    } else {
        printf("ERROR");
    }

}

int execCommand(char *command) {

    char* path[] = {"/bin/", NULL};
    printf("in execCommand > %s", command );
    strcat(path[0], command);
    execve(path[0], path, NULL);
    printf("\n");
}

at first as you can see i put the code directly in the function where the fork takes place. This would display the output expected when executing the ls command for example. But when I moved this to a function i no longer see any output.

  • 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-17T15:46:57+00:00Added an answer on May 17, 2026 at 3:46 pm

    First note that the printf() operations after the execve() are never executed if the command is executed – execve() only returns on error, never on success.

    Next, unless you include a newline at the end of the output, the print won’t be flushed to the terminal that is standard output (and there are circumstances, such as piping the standard output to another program, where even a newline is not necessarily sufficient to flush standard output). So, you should include a newline in the message, and still do fflush(stdout); before the execve().

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

Sidebar

Related Questions

int main() { ... if(!fork()) { execvp(cmdName,cmdParam); } printf(In main()...); return(0); } Assuming I
int main() { int i,j; i='c'; scanf(%d,&j); // I will read 'c' here printf(%d
int main() { double i=4; printf(%d,i); return 0; } Can anybody tell me why
int main() { int i=3; (++i)++; printf(%d,i); } This programs works with g++ compiler
int d() {return 0;} int i() {return 7;} struct a { int(*b)(); }c={d}; typedef
int RandInt(int a, int b){ return (rand()%b+a); } I want to generate the random
int int1; byte byte1; unchecked { int1 = 2147483647 + 10; //ok byte1 =
int main(){ int right[2][3] = { {1,4,6}, {2,7,5} } .... calc(right); } int calc(int
int* HT; int HTc = 500; HT = new int[HTc] = {-1}; //Fill array
I have an Android application with a background running Service. When the Service crashes

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.