with your explanation, reminding me with my teacher gave us all you talked about in less than a minute. just like we do understand everything. Again thx for this great video.
it is really incredible how you answer all questions that come up in my mind, what is your teaching experience ? :D It is second time in 15 years that I met somebody that explains so well ;).
Thanks! Aside from some volunteering work teaching highschoolers programming, I haven't taught formally at any school. I just was the guy that understood things the fastest and was always helping my peers understand too.
Is it possible, to handle the closing of a terminal through signal handler(ALT+F4)? I understand, it closes the program, But i am trying to handle a ungraceful shutdown scenario. so an ALT+F4 handler would be useful I guess. please let me know
I am a bit new to unix programming staff, so my question is: why when " " removed from printf("stop not allowed "); program requires to press Enter after ctrl+Z pressed Ctrl + Z -> Enter and then stop not allowed is written to console
The standard output (the place where printf sends the characters to be shown in the console) has a buffer. Since, for printf, outputting character by character can be very inefficient, what it does is buffer those characters in its memory and sends them all at once when it sees a new line ( ) character or other such things
for the sigaction function's third parameter, you said it helps to restaure the old handler if you need to. Could you please explain it more with an example or provide a link that show its use?
hey! can you please make a video for in-depth explanation of sigaction and it's parameters, with the internal flow of execution of how function reference works here ?
Lately, it's recommended you use sigaction instead of signal. If you go to the manual page for signal you can read the warning at the top: www.man7.org/linux/man-pages/man2/signal.2.html
What I'm most confused about is the int parameter to the signal handle functions. What gets put into there when your function is called? I imagine sending signals and using the sig value in a switch to determine how to react to the signal. Can you do this?
If I write two 'printf' in the function called by sigaction (handle_sigtstp in this case) I can only see the first printf in the terminal, then if I hit again ctrl+z I see the second one. Why is that? Thnkss for the videos, they are awesome!!
printf() functions don't work well on the sigaction function handlers since they themselves call an interrupt. This was for demonstration purposes but, usually, sigaction handlers are used for other reasons
If process parent send to his child with kill function a signial that we can't change his default comportement. If it's written on child code signal (sig kill, handler function). The action of killing will be done normally? Or the signial function will return sig err without doing the action of kill
Here I am manually launching the program as if I'm working from any other terminal... I'm just using the VSCode's built-in one. For setting up VSCode for C/C++ development, there's this video which you can check out: code-vault.net/lesson/ublnbln8uf:1603733528013
@@CodeVault I've figured out you can disable echoctl mode in your terminal like that: struct termios term; tcgetattr(0, &term); term.c_lflag &= ~(ECHOCTL); tcsetattr(0, TCSANOW, &tem); But don't forget to turn it back on in the end. Thank you for your videos and reply btw. You're doing great job
That is correct. printf is not a reentrant function and signal handlers can fire at any time. Will make a video on reentrant vs non-reentrant functions later on. This was just for presentation purposes.
It's a way clearer explanation than my teacher's one, thanks man
with your explanation, reminding me with my teacher gave us all you talked about in less than a minute. just like we do understand everything. Again thx for this great video.
you are genoius man, the way you explain is totally applaudable..!!!!, please upload the signal video about the alarm signal. Please, Please..!!!!
These videos are helping me a lot with C in my degree
Bro you have helped me with so many programming subjects at college. Greetings from Brazil.
Your videos are perfect for understanding the C Programming Language, you sure have helped many people.👍
it is really incredible how you answer all questions that come up in my mind, what is your teaching experience ? :D It is second time in 15 years that I met somebody that explains so well ;).
Thanks! Aside from some volunteering work teaching highschoolers programming, I haven't taught formally at any school. I just was the guy that understood things the fastest and was always helping my peers understand too.
@@CodeVault I was the same way in hs and still made bad grades because I didn't do the homework. Wish I could go back.
Muchas gracias :'), tus videos me estan ayudando un monton con una materia de Sistemas Operativos :'3
Thank you for this video! very good!
This is so helpful , thanks
*I NEVER FORGET TO LEAVE A LIKE BEFORE I WATCH ONE OF YOUR VIDEOS.*
The program ls in coreutils use both signal and sigaction. These days they might be able to be useful if they are used in combination.
What font are you using in VSCode?
Nice explanation sir.
Is it possible, to handle the closing of a terminal through signal handler(ALT+F4)? I understand, it closes the program, But i am trying to handle a ungraceful shutdown scenario. so an ALT+F4 handler would be useful I guess. please let me know
The hero of c programmers Lol ! Thank you ! 🥰 🥰 🥰 🥰
excellent video, nice haircut btw!
Thanks man
I always used posix signal() for that wasn’t even aware about sigaction!
thank you so much
amazing
Hey man, I appreciate your videos, they're really useful. Can you do a video on IPC?
I will look into it
I am a bit new to unix programming staff, so my question is: why when "
" removed from printf("stop not allowed
");
program requires to press Enter after ctrl+Z pressed
Ctrl + Z -> Enter
and then stop not allowed is written to console
The standard output (the place where printf sends the characters to be shown in the console) has a buffer. Since, for printf, outputting character by character can be very inefficient, what it does is buffer those characters in its memory and sends them all at once when it sees a new line (
) character or other such things
for the sigaction function's third parameter, you said it helps to restaure the old handler if you need to. Could you please explain it more with an example or provide a link that show its use?
I might make a video on this topic
Nice, what editor do you use??
Visual Studio Code
hey! can you please make a video for in-depth explanation of sigaction and it's parameters, with the internal flow of execution of how function reference works here ?
Will look into it
@@CodeVault thankyou !!
When I google the signal handling, it uses signal() function. Is the same thing as what you have done in the video? Thanks!
Lately, it's recommended you use sigaction instead of signal. If you go to the manual page for signal you can read the warning at the top: www.man7.org/linux/man-pages/man2/signal.2.html
what was the previous lesson?
Here's a link to the course: code-vault.net/course/46qpfr4tkz:1603732431896/lesson/vuiz0hwrq8:1603732432788
What I'm most confused about is the int parameter to the signal handle functions. What gets put into there when your function is called? I imagine sending signals and using the sig value in a switch to determine how to react to the signal. Can you do this?
It's the signal itself. The idea is you can use the same handler for multiple signals if you want and then switch based on it
If I write two 'printf' in the function called by sigaction (handle_sigtstp in this case) I can only see the first printf in the terminal, then if I hit again ctrl+z I see the second one. Why is that? Thnkss for the videos, they are awesome!!
printf() functions don't work well on the sigaction function handlers since they themselves call an interrupt. This was for demonstration purposes but, usually, sigaction handlers are used for other reasons
Hi do you have a video on how to implement PS in C or displaying background processes using &?
There's this video related to the topic: code-vault.net/lesson/eytyugwr7b:1603732432740
If process parent send to his child with kill function a signial that we can't change his default comportement.
If it's written on child code signal (sig kill, handler function).
The action of killing will be done normally? Or the signial function will return sig err without doing the action of kill
You can try to experiment it yourself. But basically the code in the handler won't execute
how are you able to get input in the debug terminal with visual studio code
Here I am manually launching the program as if I'm working from any other terminal... I'm just using the VSCode's built-in one. For setting up VSCode for C/C++ development, there's this video which you can check out: code-vault.net/lesson/ublnbln8uf:1603733528013
Can you also make a video on how to Invoke Signals with a Payload/Argument with the help of sigqueue() and SA_SIGINFO flag. Thank you.
Yes, I'll look into it
спасибо
Is it save to use printf() in the signal handler, i heard that this will cause errors and crashes?
No, it's not really. It was meant only for demonstration purposes
@@CodeVault okay ty ;)
Huh i don't know why this works differently on mac.. when i hit fg, it still prints the (result ) even tho it actually stopped
The videos are made mostly for Linux. I will look into why there are these differences between the OSes
How we do to turn program in the background ?
There's this video on the topic: code-vault.net/lesson/eytyugwr7b:1603732432740
hi shouldn t u use write in the signal handler since it is an async signal printf could give errors instead write should be used
Yes, you are correct. But this was just for demonstration purposes
Yes, you are correct. In a production environment you shouldn't do any read/write operations in a signal handler
Anyone know of a way to also pass a parameter to the signal handler using sigaction?
You cannot really pass parameters to those handlers. They are only made to handle signals. If you need to pass data to other processes use pipes
How to handle multiple signals using sigaction?
Just put a bitwise OR between the signals you want to catch:
sa.sa_flags = SIGUSR1 | SIGUSR2;
@@CodeVault sa.sa_handler = &SIGHDLR1 | &SIGHDLR2 ?
No, that's only for the sa_flags. If you want to catch two different signals in two different handlers then simply create to sigactions
@@CodeVault Just found the answer without even need to ask!!!! Deeply grateful!!!
anyone has any ideas on how to get rid from that ^Z in the beginning of the line?
It's just something that's added to the terminal itself... I know it doesn't have anything to do with the program you're running
@@CodeVault I've figured out you can disable echoctl mode in your terminal like that:
struct termios term;
tcgetattr(0, &term);
term.c_lflag &= ~(ECHOCTL);
tcsetattr(0, TCSANOW, &tem);
But don't forget to turn it back on in the end.
Thank you for your videos and reply btw. You're doing great job
printf is not safe and shouldn't be used with signal handling. It will cause crashes and unexpected behaviors.
That is correct. printf is not a reentrant function and signal handlers can fire at any time. Will make a video on reentrant vs non-reentrant functions later on. This was just for presentation purposes.