Fork and Exec Linux Programming
HTML-код
- Опубликовано: 2 июн 2024
- Demo using fork and exec to run an executable from disk in a new process. Show how to pass arguments, wait for child to complete, and how to spawn multiple children. Shows advantage of using multiple processes over a single process in terms of using CPU power of multiple processors (cores).
Other Videos:
- Fork: • Linux fork() Introduction
- Exec: • Linux Exec System Call
- Eclipse Linux setup: • C Makefile Project in ...
- Linux Programming playlist: • C Makefile Project in ...
Hello, you didn't show us the bogosort file. Can you or anyone put here the code for that algorithm?
thank you for making these videos. it is really helping me in class a lot!
This is helping a whole bunch write a shell program. Thank you !!!!
Great explanation! Helped a lot with my lab assignment.
THANK YOU!!!!
Really nice way to explain processes, showing sys utilization. Great help Sir. Thanks!!
Thank you for these very informative videos.
Excellent tutorial man, thank you so much
thank you for your tutorial. It helps me a lot to understand fork and exec :D
Thank you very much for this tutorial. I wish you do one for Kernal programming
Nice tuts, but I still have a few questions:
0.what happens if you allocate memory on the heap before calling fork and exec?
1.how can I communicate between the parent and the forked process (beyond just getting child's return value)
2.i forked my program, and exec'ed some other binary(from the child). the binary prints stuff out to the cli. Can I get its output from the parent code? Is popen() better suited for that kind of stuff?
Much love from TU Graz
what if one of the arguments passed in is "&" so that it is a background command when doing bash arguments? does exec recognize this?
Sir! I have a scenario.. Can we take inputs using exec system call?
As fork() returns two values, then how we are going to return those two values using exec(). If it makes sense, Please do a short program on execlp() taking two inputs from user and returning two values(one to the child process and other value to the parent process).. and it actually performs a task there like making a directory or pings for a website etc.
Regards!
Thank you so much for the tutorial, it is really helpful. :D
Great explanation! Thanks!
great work sir, thank you a lot.
Your explanation is really amazing👍👍
I got so much help!!! Thank you!!!!!
Awesome, great videos!
is there any way to make the fork even faster?
Hi sir, Hope you are good, have doubt in threading, can you help me. how can i get in touch with you regarding the same, Thanks
@brian fraser
Thank you very much , is there a way to make the children do different tasks for example I want one to sort and the other get the sum or average and so on ? Thank you
+Muhanad Ahmad Yes you would need to call fork twice to create two children processes. and also run two if checks.
+Muhanad Ahmad I believe you can create a function called ChildWork(int i); -> inside the function have a switch statement that does different sorts of work depending on if the child's integer value (iteration of i) is 1,2,3 etc.. -> place that function in the child else if part of his main code and pass in i)
תודה רבה !
thanks!!!!
Nice sir
Thanks
What IDE is that ?
John Doherty Looks like Eclipse
nice tut, is this donald sutherland ?
I cant understand why the parent need to wait for the child or the program would never end. It is the part around 8 mins.
+Klose Ho A bit late, the answer is no he made another video on this.
And Which video is that ? Could you share the link ?
TYFYS
breh u didn't talk about bogosort.c
rosettacode.org/wiki/Sorting_algorithms/Bogosort#C
Edit: here is what I used, adapted from above:
#include
#include
#include
#include
#include
bool isSorted(int *a, int n)
{
while ( --n >= 1)
{
//printf("
not sorted..
");
if ( a[n] < a[n-1] ) return false;
}
//printf("
sorted..
");
return true;
}
// LOL
void shuffle(int *a, int n)
{
//printf("
shufflin..
");
int t, r;
for (int i = 0; i < n; ++i)
{
t = a[i];
r = rand() % n;
a[i] = a[r];
a[r] = t;
}
}
void bogosort(int *a, int n)
{
while (!isSorted(a, n)) shuffle(a, n);
}
int main(int argc, char* argv[])
{
srand(time(NULL));
// read numbers from input
int n = argc-1;
int* a = (int *)malloc(sizeof(int)*n);
for (int i = 1; i
Ugh I hate how none of these videos go into any detail. Can't one of them at least describe more complex trees
Hello Khan academy?
suppu what ra????????