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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:56:19+00:00 2026-05-26T12:56:19+00:00

I am trying to execute LP to print a PDF document and wait for

  • 0

I am trying to execute LP to print a PDF document and wait for it to exit. After
it exists i am trying to delete the file with unlink();

However the wait finishes even before execv execute LP. I am not quite sure
how to handle this and why the wait isn’t waiting till execv finishes.

Is there any other way to accomplish this?

        if(fork())
        {
            fprintf(stderr, "Executing command %s %s", "/usr/bin/lp", homedir);
            char *const parmList[] = {"/usr/bin/lp", homedir, (char *)0};
            execv("/usr/bin/lp", parmList );

        }else
        {
            int pid, status;
            fprintf(stderr, "Wait\n");
            pid = wait(&status);
            fprintf(stderr, "Finished waiting.\n");
            unlink(homedir);
        }

When executing the above code the ouput would look like this:

Wait
Finished waiting.
Executing command /usr/bin/lp /home/user/Docs/test.pdf
/usr/bin/lp: Error - unable to access "/home/user/Docs/test.pdf" - No such file or directory
  • 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-26T12:56:19+00:00Added an answer on May 26, 2026 at 12:56 pm

    fork() returns zero in the child process, and a positive value in the parent process (assuming the fork succeeds), and wait(...) only makes sense in the parent process, so you need to swap the contents of your if and else blocks.

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

Sidebar

Related Questions

I am trying to execute this SQL query prior to restoring a .BAK file
I'm trying to execute the following line: exit | sqlplus username/password@sid @test.sql Works great
I am trying to return (execute) a function from another file in an if
I am trying to print (to a text file) the fragmentation information give by
While trying to execute the following lines only the last two statements are displayed(Here
I am trying to execute a stored procedured from a linked database in MS
I am trying to execute this SQL command: SELECT page.page_namespace, pagelinks.pl_namespace, COUNT(*) FROM page,
I'm trying to execute a asp.net webservice using jquery. When I pass only one
I am trying to execute this but cant see any result: <script> function init()
I am trying to execute a certain task where i am required to read

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.