Fork and Commands
Write the application or program to open applications of Linux by creating new processes using fork system call. Comment on how various application’s/command’s process get created in linux.
#include<stdio.h> #include<stdlib.h> int main(){ int val,ret,proc; char app1[10],app2[10]; printf("\nThis is the program to illustrate the use of fork and exec system call family-->>"); printf("\nEnter name and command of any two applications you want to run on this linux!"); scanf("%s%s",&app1,app2); printf(app1); printf(app2); proc = fork(); if(proc == 0) { printf("\n Forked process executing this app ..btw"); ret = execlp (app1, app1, "-l", (char *)0); } if(proc) { printf("\n main process executing this app ..btw"); ret = execlp (app2, app2, "-l", (char *)0); } return; Plaese Comment |
Okay, here is a comment: your code would be more readable is you used [code] and [/code] tags.
|
} // This to terminate your main ;)
- the second argument of scanf is wrong. It should be app1, not &app1. And good compilers signal that as a warning ... - You could have written "else" instead of "if (fork)" - You never use the value of ret. You should because execlp does NOT return unless there is a problem in which case the value of ret may be useful to understand the error - Why do you add a "-l" argument to your commands ? - the printf in each case could expose the value of app1 (app2) - I don't like scanf - what will happen if you enter commands greater than 9 characters ? :tisk: |
You should rewrite your original post in this way:
Quote:
If the answer is "yes," then y-o-u are going to have to be the one to do it. There is no other way. |
All times are GMT -5. The time now is 06:38 AM. |