Thread: execl failing

  1. #1

    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");

    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


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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).

    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.

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