execl failing

This is a discussion on execl failing within the C Programming forums, part of the General Programming Boards category; I am trying to run execl from a child process. it runs another program I wrote called producer, which takes ...

  1. #1
    carrythe0
    Guest

    Thumbs down execl failing

    I am trying to run execl from a child process. it runs another program I wrote called producer, which takes two parameters: a single char and an int. the producer program is in the same directory as the parent. here is what I have:

    if(fork() == 0){
    if((execl("./producer", "producer", 'A', 0, NULL)) == -1){
    perror("execl failed");
    exit(1);
    }

    there are actually two producers, A and B, and when I run the program, I get these error messages:

    execl producer A failed: bad address
    execl producer B failed: bad address

    why?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,556
    All the args should be const char *'s

    'A' is an integer, which when cast to a pointer will be something like 0x00000041 (this isn't good).

    So
    if((execl("./producer", "producer", "A", "0", NULL)) == -1){

    In your producer, which has
    int main ( int argc, char *argv[] ).....
    argv[0] == "producer"
    argv[1] == "A"
    argv[2] == "0"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using execl()
    By dudeomanodude in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2010, 02:13 AM
  2. execl and command line arguments
    By imtiaz3 in forum C Programming
    Replies: 13
    Last Post: 09-30-2008, 12:18 PM
  3. pointer comparison failing
    By Bleech in forum C Programming
    Replies: 4
    Last Post: 08-11-2007, 06:33 PM
  4. Can we use select() to capture output from execl()?
    By Nessarose in forum Networking/Device Communication
    Replies: 5
    Last Post: 07-05-2005, 12:53 AM
  5. initializes all components of failing to false
    By romeoz in forum C++ Programming
    Replies: 21
    Last Post: 08-01-2003, 09:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21