Results 1 to 5 of 5

Thread: exec() usage? what am I doing wrong?

  1. #1
    Join Date
    Nov 2008
    Location
    Maine
    Beans
    1,126
    Distro
    Ubuntu 10.04 Lucid Lynx

    exec() usage? what am I doing wrong?

    Code:
    #include <sys/types.h>
    #include <sys/types.h>
    #include <sys/wait.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <unistd.h> //required by execl
    #include <stdio.h>
    
    int pid, ppid;
    
    int main()
    {
    pid=getpid();
    printf("PID of this process is: %x\n",pid);
    	if (fork()==0){
    		pid=getpid();
    		ppid=getppid();
    		printf("I'm in the Replica and my PID is: %x\n",pid);
    		printf("... About to execute my Program, PID should be the same\n");
    		printf("... PID of parent process is: %x\n",ppid);
    		execl("./myprog", NULL);}
    pid = waitpid ((pid_t)-1, NULL, WNOHANG);
    return 0;
    }
    line with: execl("./myprog", NULL);}
    gets these warnings?
    FEW.c:21:3: warning: null argument where non-null required (argument 2) [-Wnonnull]
    FEW.c:21:3: warning: not enough variable arguments to fit a sentinel [-Wformat]

    I have read the man page for execl But.. I dont know what to put in the place of null. I am not trying to pass arguments to myprog (located in the same directory).
    what should I put in the place of NULL? how do i fix these warnings?
    ~Conradin~

  2. #2
    Join Date
    Nov 2008
    Location
    Maine
    Beans
    1,126
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: exec() usage? what am I doing wrong?

    Also, When i run this I see some threads with leters in them?
    such as:

    ....
    PID of this process is: 168b
    I'm in the Replica and my PID is: 168c
    ....

    Ive never seen a PID with a letter in it. is this a pruduct of bad coding? or a normal occurance?
    ~Conradin~

  3. #3
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: exec() usage? what am I doing wrong?

    Quote Originally Posted by conradin View Post
    Also, When i run this I see some threads with leters in them?
    such as:

    ....
    PID of this process is: 168b
    I'm in the Replica and my PID is: 168c
    ....

    Ive never seen a PID with a letter in it. is this a pruduct of bad coding? or a normal occurance?
    As per the man page, you want
    Code:
        execl("./myprog", "./myprog", NULL);
    The second argument is arg0.

    When you pass %x to printf, you are asking for the PID it be displayed in hexadecimal - hence the letters.

  4. #4
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: exec() usage? what am I doing wrong?

    Quote Originally Posted by spjackson View Post
    As per the man page, you want
    Code:
        execl("./myprog", "./myprog", NULL);
    (char*)NULL, please.
    「明後日の夕方には帰ってるからね。」


  5. #5
    Join Date
    Nov 2008
    Location
    Maine
    Beans
    1,126
    Distro
    Ubuntu 10.04 Lucid Lynx

    Solved: Re: exec() usage? what am I doing wrong?

    maybe my reading gland was ailing yesterday.
    Thank you both for the assistance
    Last edited by conradin; August 7th, 2013 at 08:47 PM. Reason: Solved
    ~Conradin~

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •