No video

Getting exit status code in C

  Рет қаралды 38,303

CodeVault

CodeVault

Күн бұрын

More details on wstatus: man7.org/linux...
Check out our Discord server: / discord

Пікірлер: 38
@zyghom
@zyghom 2 жыл бұрын
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 жыл бұрын
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 7 ай бұрын
Been battling with this issue all day today, your video has saved me. Thank you!!
@joroh_
@joroh_ 4 жыл бұрын
Thank you, very useful courses, keep going sir.
@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 Жыл бұрын
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
@lyricsmaker-poplyricsmaker1183
@lyricsmaker-poplyricsmaker1183 4 жыл бұрын
You areee really helpingg sir thaanks
@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 Жыл бұрын
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!
@poincareelcartografo5406
@poincareelcartografo5406 Жыл бұрын
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 Жыл бұрын
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
@user-hg4ef7jm9l
@user-hg4ef7jm9l 6 ай бұрын
I have compiled your code many times, child always returns 1 on success and failure both. I wonder why ...
@CodeVault
@CodeVault 6 ай бұрын
Make sure you call execlp with valid parameters. Maybe you are missing "ping" from PATH
@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 3 жыл бұрын
I want to create a c/c++ program to run MULTIPLE (say 10) c/c++ programs please help 🙏
@abdullahsohail1781
@abdullahsohail1781 Жыл бұрын
Amaizing--------------------------thanks a lot 🤩
@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 Жыл бұрын
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
@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 жыл бұрын
You can always call read inside the signal handler... although it's not recommended. Signals are not really designed to send/receive data.
@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 жыл бұрын
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!
@narendraparmar1631
@narendraparmar1631 3 жыл бұрын
Thanks 😁
@navidnouri151
@navidnouri151 2 жыл бұрын
Thank you a l 000^1000 t!
@ismailskizof1279
@ismailskizof1279 Жыл бұрын
thanks from 1337
@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.
@sambanasreeja2606
@sambanasreeja2606 3 жыл бұрын
can you do video on semaphore code ?
@CodeVault
@CodeVault 3 жыл бұрын
Will look into it!
@sparsetable
@sparsetable Жыл бұрын
giga brain
@andelephantscanfly
@andelephantscanfly 3 жыл бұрын
i would be really surprised if your hight is 2m xd xd
Redirecting standard output in C
15:39
CodeVault
Рет қаралды 90 М.
How to execute another program in C (using exec)
14:23
CodeVault
Рет қаралды 104 М.
Comfortable 🤣 #comedy #funny
00:34
Micky Makeover
Рет қаралды 17 МЛН
Идеально повторил? Хотите вторую часть?
00:13
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 18 МЛН
Coding a Web Server in 25 Lines - Computerphile
17:49
Computerphile
Рет қаралды 333 М.
Calling fork multiple times
13:58
CodeVault
Рет қаралды 108 М.
Why Function Pointers are Awesome
11:11
Jacob Beningo
Рет қаралды 6 М.
why do header files even exist?
10:53
Low Level Learning
Рет қаралды 393 М.
Writing Code That Runs FAST on a GPU
15:32
Low Level Learning
Рет қаралды 553 М.
What are variadic functions (va_list) in C?
13:49
CodeVault
Рет қаралды 21 М.
Using Strace to Trace Linux Syscalls
16:20
LaurieWired
Рет қаралды 15 М.
Simulating the pipe "|" operator in C
19:52
CodeVault
Рет қаралды 82 М.
~/.dotfiles in 100 Seconds
13:54
Fireship
Рет қаралды 415 М.
String In Char Array VS. Pointer To String Literal | C Programming Tutorial
9:58
Comfortable 🤣 #comedy #funny
00:34
Micky Makeover
Рет қаралды 17 МЛН