Getting exit status code in C

Поделиться
HTML-код
  • Опубликовано: 16 май 2020
  • More details on wstatus: man7.org/linux/man-pages/man2...
    Check out our Discord server: / discord

Комментарии • 38

  • @zyghom
    @zyghom 2 года назад +6

    so far I spent literally hours on your channel
    not done yet
    so next one goes now
    your way of explaining really matches my ways of learning ;-)

  • @albertocaravantesarranz9492
    @albertocaravantesarranz9492 2 года назад +4

    1 hour trying to get error codes from a child process and in 5 minutes you gave me the answer. Love your channel :-D

  • @user-hy1lm2rd9q
    @user-hy1lm2rd9q 4 месяца назад

    Been battling with this issue all day today, your video has saved me. Thank you!!

  • @joroh_
    @joroh_ 4 года назад +8

    Thank you, very useful courses, keep going sir.

  • @lyricsmaker-poplyricsmaker1183
    @lyricsmaker-poplyricsmaker1183 4 года назад +2

    You areee really helpingg sir thaanks

  • @abdullahsohail1781
    @abdullahsohail1781 Год назад

    Amaizing--------------------------thanks a lot
    🤩

  • @narendraparmar1631
    @narendraparmar1631 3 года назад

    Thanks 😁

  • @ShannonWare
    @ShannonWare Год назад

    Perhaps you will answer this question later in this series, but I am wondering how to see the exit code when I run main or some other binary from the command line. Especially when I compile and run with VS Code, the 0 from return 0 is not shown in the Terminal. Thanks!

    • @CodeVault
      @CodeVault  Год назад +1

      If you run this in bash: echo $?
      You should get the exit code of the previously executed command

    • @ShannonWare
      @ShannonWare Год назад

      @@CodeVault that is amazing thank you so much!

  • @yassinemakhlouf9907
    @yassinemakhlouf9907 Год назад

    another problem i faced is the return status gets modulo by 256, so when you return 256 in this case it's actually like you returned 0 and it show "success" even thought "ping" is misspelled

    • @CodeVault
      @CodeVault  Год назад +1

      That's the limit of different exit codes on Linux it seems like. Although there looks to be ways to get the whole 32-bit integer that was returned by the process. Here are more details: stackoverflow.com/questions/179565/exitcodes-bigger-than-255-possible

  • @Be_Deep_In_Thoughts
    @Be_Deep_In_Thoughts 2 года назад

    I am newbie, so just curious, the wstatus is just an integer right? Can it have a different name or is it a part of some nomenclature to follow?

    • @CodeVault
      @CodeVault  2 года назад

      The variable's name doesn't matter. And yes it's an integer. wstatus is simply the name of the function's parameter
      Here you can read up more on this topic: www.man7.org/linux/man-pages/man2/waitpid.2.html

    • @Be_Deep_In_Thoughts
      @Be_Deep_In_Thoughts 2 года назад

      @@CodeVault Thank you for your response. I follow your videos meticulously and I just love them. Thank you for your quality content.

  • @ShivamSharma-nb6gh
    @ShivamSharma-nb6gh 2 года назад

    I want to create a c/c++ program to run MULTIPLE (say 10) c/c++ programs please help 🙏

  • @migueldomingues6871
    @migueldomingues6871 3 года назад

    Hello, can you tell me how I can receive a value from the child process when it receives a signal?! To clarify, the parent sends a signal to the child, and the child should return a pontuatuion (int). Ty, love your videos!

    • @CodeVault
      @CodeVault  3 года назад +1

      You can always call read inside the signal handler... although it's not recommended. Signals are not really designed to send/receive data.

  • @yassinemakhlouf9907
    @yassinemakhlouf9907 Год назад

    How to differentiate between the exit code 2 when received from the childprocess because ping was misspelled or the 2 that got returned from the ping program because the domain name was misspelled

    • @CodeVault
      @CodeVault  Год назад +1

      You can simply check the return value of exec and then look at errno to find out what exactly happened for the first case and return a different error code than the one returned by ping. Here's more documentation on the topic: linux.die.net/man/2/execve

  • @madvillain285
    @madvillain285 3 года назад

    there is a way to execute a command and get the stdout and the exit code?
    i know i can get the output using popen(), but with this function i can't get the exit code
    any suggestion, or something I can start from

    • @CodeVault
      @CodeVault  3 года назад +1

      You could redirect the standard output to some pipe that then you can do whatever you want with in a parent process, here's a video on this: code-vault.net/lesson/43zvcsz6o1:1603732432539

    • @madvillain285
      @madvillain285 3 года назад

      @@CodeVault thanks bro, you really help me!

  • @sparsetable
    @sparsetable 10 месяцев назад

    giga brain

  • @poincareelcartografo5406
    @poincareelcartografo5406 11 месяцев назад

    But if you misspell the program name (pong instead of ping), you will get the "Could not find the program" message and also the "Success!" message, because the statusCode was 0 even though _execlp() could not find the program.

    • @CodeVault
      @CodeVault  10 месяцев назад

      Interesting, I wonder why it doesn't return a proper error status code. Although, I guess, if you're executing anything after execlp, it already means the call failed and you can print an error message

  • @navidnouri151
    @navidnouri151 2 года назад +1

    Thank you a l 000^1000 t!

  • @ismailskizof1279
    @ismailskizof1279 Год назад

    thanks from 1337

  • @user-hg4ef7jm9l
    @user-hg4ef7jm9l 4 месяца назад

    I have compiled your code many times, child always returns 1 on success and failure both. I wonder why ...

    • @CodeVault
      @CodeVault  4 месяца назад +1

      Make sure you call execlp with valid parameters. Maybe you are missing "ping" from PATH

  • @sambanasreeja2606
    @sambanasreeja2606 3 года назад

    can you do video on semaphore code ?

    • @CodeVault
      @CodeVault  3 года назад +2

      Will look into it!

  • @miaaaslifestyle9575
    @miaaaslifestyle9575 3 года назад

    So the user can click that link and it takes them to google??

    • @CodeVault
      @CodeVault  3 года назад

      You mean the link google.com? Yes, of course.

  • @andelephantscanfly
    @andelephantscanfly 2 года назад

    i would be really surprised if your hight is 2m xd xd