As a continuation to what we looked at in the last video, which you can check up top where we try to just execute a simple program, The ping program in our own program while also being able to do something else other than just executing it using Fork. So we have here a fork and then in the child process, we executed this pink program, but in the parent also, we just waited for the pink program program to finish its execution. And then we did some post-processing now. I didn’t look at how to check. If this program that we launched a actually succeeded, okay, so if we launch the program. How do we check if it actually succeeded or if we got some? Arabs. Well, there are two types of Arabs here. One is if the actual ping program does not exist is not found or two if the actual ping is found is executed, but it gives out an error. How can we treat each of the error types here well? The first one is very simple. What we have to do is remember that exact, in fact does basically replace all the code and all the memory of our current process, only if it’s successful only if it’s successful in finding the program that it needs to execute and so on and so forth. If it doesn’t find it if something’s wrong with the name of the program that it does, in fact, not replace the code and it continues its execution, okay, so it, in fact will return a an integral that represents. Well, whether or not it was successful so here we can say error equals the return value of this exact and if error is negative one, which is most likely gonna be. I think it can actually return anything other than negative one, because well, if it’s successful, just replaced and nothing executes after the exact function. So that’s what happens, but if well we’re gonna just be safe and actually check if it’s negative one, if it is, we can just printf would not find program to execute next to shine or something like that and just return return zero. I got so as you can see. It is actually ping to googlecom or K 64 bytes it. It took like 15 milliseconds. It works and then we do print out these messages after the ping program works. That’s nice, But what if the ping is actually wrongly spelled say? I type in Ping R, for example, And if I launch this, what’s gonna happen then? Well, in that case, you’ll notice that we do. Indeed, Printf could not find a program to execute. So in this case, it didn’t find a program to execute so it did not execute It did not replace the code and it just continued. It’s execution now. Then what if it is successful in finding the program? But instead let’s see we don’t type in the right domain name and let’s say we type in googlecom. Let’s say if we try to launch this. You’re gonna notice that we do get in the pink in the pink program. We do get a message saying that the name or service is not known, of course, doesn’t exist. It doesn’t know how to ping to it, but we just say success here, even though the ping did not succeed. How do we know it’s in it? How can we find out if it did succeed? Well, that answer lies in the weight function. So remember, every time we call The weight was with the null here with an old parameter, and there was it. In fact, this this parameter tells us some information about what happened with the child process. Okay, so it is an INT pointer, so we we actually declare here unpinned. Let’s call it weight status and we pass in a reference to it. W status, okay, and after this has executed. Something will be populated into here. That will tell us what happened, but we have to make use of some macros to be able to find out now. There are two checks that we have to do with this. W Status. So after it finished execution, we have to test if the if the code if the program just simply terminated on its own. Right, so nothing actually occurred. There was no external signal, for example, When you when you, for example in the task manager and try to kill the task, you wouldn’t be a normal termination of the problem. Well, just something external would just terminate the process similarly in Linux. You can do this you by sending the sync kill signal. Well, you have two signals in a later video, but just keep in mind that this sick kill. Basically, if you send it to a process, it just tell me the process. We’ll, not normally so to check. If the process terminated normally, we can say if and we can call the gif or W if exited macro, this is a macro that takes in the W status. So if this guy this W if exited, returns true or returns something different than zero then. We know that what happened here was normal termination, so the program finishes execution normally next up, we can actually take the status code that that pink program exited with so you can say here. Int status code equals. W exit status of W status. So this is going to return our status code. What is that status code that I am talking about that? Is the return value inside the main or the value that it exited with using the exit? Call so remember this. This is our status code. This is what we’re returning. So here we are telling the. Er, thing, OK? That program executed properly here up top, we’re returning one, saying that the point did not execute, did not finish properly and something bad happens, in fact, every single. Linux program has that has that returned at either in the main function or it has an exit call of one. These two are basically the same. It’s just that you can call exit. One whatever you don’t have to have it inside the main function anyway in Linux, a exists code that is not zero signifies an error so here we have one as an error or here, we should probably type in instead of returns or in return to because it is an error, in fact, and here we have written zero so we can say status code. Is this so if the status code is zero? Then we know that it was a success in executing the program. Otherwise we can say print. F failure failure. Backslash, N. And yeah, that’s about it. We can leave this printf here. Why not, but this status code should really always be zero for programs that have executed properly. If it’s not, it’s an error, so we can. If we try to run this now, you will notice something interesting as you can see. It did say that the googlecom name or service is not known in ping. So that’s fine, but here we have printed failure. This is from our parent process, so indeed the status code that we got was not zero. We can actually check which status call we got so we can see failure with status code percent. D and we can have it here. Status code. And if I try to launch this, we should get. I think it was a status code. – now this – here doesn’t really have any intrinsic meaning for ping is just saying that it is just another error if we were if we were to get one. I would mean that we didn’t get a response from the server. This is another error thing that we probably did not actually even get to the server because again googlecom with an N and E and does not exist, so it doesn’t know how to ping that and again, Instead of CO2 from the ping doesn’t mean that it’s the same error for other programs, right, so two for ping means other errors, but for other programs with your own program that could mean a specific error saying. Something went wrong with. I don’t know, opening the pipe or as Ts for us here. Something went wrong with executing the child process. I would, that’s the tool at it. It’s in here, but these two shouldn’t be confused with this one. These two is actually from the pink program. This is actually from our own problem, okay, and, of course, if we do change this back to Chrome. So it says googlecom and it is valid if we launched this what we are going to get is a proper success message that means that the status code that we got here was, in fact zero, and if it’s zero, everything went smoothly and we did, in fact, get some pings to googlecom there are all sorts of information You can get from this. W status. I’m going to leave a link in the description. If you want to check it out otherwise. I hope you got something out of this video. If you do have any questions, please leave them down a comment below or on our discord server. Take care bye you.