Linux fork, execv, wait question


 
Thread Tools Search this Thread
Top Forums Programming Linux fork, execv, wait question
# 1  
Old 11-19-2012
Linux fork, execv, wait question

Hi All,

I have a program for class that needs to do the following:
1. Print the directory entries from the current directory using ncurses
2. Provide a prompt next to each directory entry and allow the user to enter commands that may or may not be about the file
3. Execute those commands in sequence

My question is this:
How can I use fork, execv, and wait to allow for commands that also use ncurses or stdin/stdout to do what they need to do and then restore my ncurses program.

Example:

Say I want to execute "ls /etc/ | more". If I use system() the output is jumbled like this: Image

How do I make it so that when I press ENTER, the output of more is exactly as you would see it if you opened the terminal and typed it, and then after more terminates, my ncurses program reappears as if nothing happened.

It seems like if I were to use execv it would accomplish what I want because from the man pages: "The exec family of functions replaces the current process image with a new process image." If I were to replace a child process image with the process image of "more", it should achieve what I want correct? Can anyone please provide me with some insight?

Thanks for reading
# 2  
Old 11-19-2012
Please post this in the homework forum. Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

question about fork

i'm experimenting fork function and i found this code #include <stdio.h> #include <sys/stat.h> #include <sys/types.h> #include <wait.h> #include <fcntl.h> #include <unistd.h> int main(void) { int fd; pid_t p; p = fork(); fork(); if (p>0) { fork();} fork(); fork();... (6 Replies)
Discussion started by: blob84
6 Replies

2. Programming

Newbie question on exec,fork, wait,pipe C

Hello everybody.I want to make clear that i am not going to ask from anybody to build my asignement but i have a big problem. I can't seem to find anywhere ONE good example on C about what i am trying to do:wall:.I think it is simple. All i ask is one example, even a link is fine. So, i want to... (1 Reply)
Discussion started by: Cuervo
1 Replies

3. Programming

multiple fork() question

I writing a program that forks three times but only on the parent process. The three children processes then produces output in order. 1, 2, 3. I am confused on how to do this. I have tried multiple if and else if statements but the output does not come out right. How should I go about doing this? (1 Reply)
Discussion started by: TWhitt24
1 Replies

4. Programming

Beginners question about fork

Hi everyone: I'm developing a dynamic library for notifications, this library is used for a daemon that i've programmed, when something goes wrong the library should send an email to an administrator, but since sending an email is a non-vital process then it can fail (it should work as an... (4 Replies)
Discussion started by: edgarvm
4 Replies

5. Shell Programming and Scripting

Question about wait

I have a shell script that i want to run and then wait 30 minutes before running the rest of the script. When I google the "wait" command, it seems to work for waiting for child processes or some pid to stop. How do I wait for 30 minutes before continuing? (2 Replies)
Discussion started by: guessingo
2 Replies

6. Red Hat

Fork wait in background process - large delay

hi all, We are trying to run a process in the background and in the process we call fork ;and wait for the child process to finish .We find that the died = wait(&status); happens after 10 seconds randomly and sometimes completes in time (within 1 sec) This behavior is seen only when the... (1 Reply)
Discussion started by: vishnu.priya
1 Replies

7. Red Hat

Fork wait in background process - large delay

hi all, We are trying to run a process in the background and in the process we call fork ;and wait for the child process to finish .We find that the died = wait(&status); happens after 10 seconds randomly and sometimes completes in time (within 1 sec) This behavior is seen only when the... (0 Replies)
Discussion started by: vishnu.priya
0 Replies

8. UNIX for Dummies Questions & Answers

How can i use fork,sleep,wait and write in a process with father and son..??

Hi.. I was unable to do (gcc code) which refers to the fork,wait,sleep and write.. what i want to do: A process of father create (fork) a son and will sleep 90 seconds..After this, son process create a grandchild and will sleep 60 seconds..Grandchild process will sleep for 30 seconds..After... (3 Replies)
Discussion started by: gumlucin
3 Replies

9. AIX

Question on High I/O Wait

Hi Group, We have 4 p590 with AIX 5.2 and ML06. The servers are connected to the external SAN (hitachi drives). When running the vmstat or topas command, I see that there is a high I/O wait. It sometimes crosses 90% and the average is over 55%. The server is expeiencing high performance... (0 Replies)
Discussion started by: brookingsd
0 Replies

10. Programming

simple fork question

When executing this simple program: #include <unistd.h> void main() { int f; printf("\n Parent procces ID=%d\n",getpid()); f=fork(); if(f==0) { printf("\n Child process ID=%d father=%d\n",getpid(),getppid()); } ... (2 Replies)
Discussion started by: bb666
2 Replies
Login or Register to Ask a Question