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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:21:10+00:00 2026-06-17T21:21:10+00:00

Possible Duplicate: Writing a shell – how to execute commands I’ve been tasked with

  • 0

Possible Duplicate:
Writing a shell – how to execute commands

I’ve been tasked with writing a shell in C. So far I understand that execvp will try to run the program in arg1 with arg2 as parameters. Now it seems that doing this

execvp ("ls", args); //assume args is {"ls", ">", "awd.txt"}

is not equivalent to typing this in the console

ls > awd.txt

I realize that I need to use freopen to achieve the same results but I’m curious what execvp is doing.

  • 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-17T21:21:12+00:00Added an answer on June 17, 2026 at 9:21 pm

    The exec family of functions are ultimately a system call. System calls go straight into the kernel and typically perform a very specific service that only the kernel can do.

    Redirection, on the other hand, is a shell feature.

    So, when one types ls > awd.txt at a shell, the shell first does a fork(2), then it closes standard output in the child, then it opens awd.txt on file descriptor one so that it’s the new standard output.

    Then, and only then, the shell will make an exec-family system call.

    In your case you simply passed the strings > and awd.txt to the exec system call, and from there to ls. BTW, be sure you terminate your execvp arg array with a null pointer.


    Note: As you can see, the redirection operators are never seen by the executed program. Before Unix, directing output to a file had to be done by every program based on an option. More trivia: most programs never know they were redirected, but ironically, ls does check to see if its output is a tty, and if so, it does the multi-column formatted output thing.

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

Sidebar

Related Questions

Possible Duplicate: Choose order to execute JUnit tests I am writing a JUnit test.
Possible Duplicate: Yield In VB.NET In C#, when writing a function that returns an
Possible Duplicate: Double calculation producing odd result I'm writing a program in Java that
Possible Duplicate: Get Correct keyCode for keypad(numpad) keys I'm writing an application that needs
Possible Duplicate: Workflow for statistical analysis and report writing I have been programming with
Possible Duplicate: String.replaceAll() anomaly with greedy quantifiers in regex I was writing code that
Possible Duplicate: Writing C# Plugin System Is it possible to write a program that
Possible Duplicate: Is sizeof(bool) implementation defined in C++? Im writing code that is compiled
Possible Duplicate: regexp to partly hide email? I'm currently writing a script that hides
Possible Duplicate: Check orientation on Android phone I am writing an app that requires

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.