1

I am writing code in C in a Linux terminal trying to display CPU info when the command is run.

execl ( "/bin/lscpu","lscpu",(char*)0);

I have tried everything and can't seem to find the answer that works. This command is giving me a blank and not sure how my execl command should look here.

bolov
  • 72,283
  • 15
  • 145
  • 224
this.mehhh
  • 11
  • 4

1 Answers1

0

Check that the specified path to lscpu is correct,

ls -altr /bin/lscpu

Where is lscpu located?

which lscpu
ls -altr /bin/lscpu /usr/bin/lscpu

Inspect the error returned (the following works),

#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>

int main() {
    int err;
    err = execl( "/bin/lscpu","lscpu",(char*)0 );
    if( err != 0 ) {
        printf("errno=%d: %s\n",errno,strerror(errno));
    }
}

If you replace the pathname (append an 'X'), you will get an error,

err = execl( "/bin/lscpuX","lscpu",(char*)0 );
ChuckCottrill
  • 4,360
  • 2
  • 24
  • 42