execv

How to bring a child process running in the background to the foreground

℡╲_俬逩灬. 提交于 2019-12-02 05:33:26
问题 If I used fork() and execv() to spawn several child processes running in the background and I wanted to bring one of them to the foreground, how could I do that? I am trying to write a shell that can start processes either in the foreground or background. 回答1: "Background" and "foreground" are not terms used generically for processes, but rather only apply to shells which can wait for jobs on demand. 回答2: Complimentarily to Ignacio Vazquez-Abram's answer, I suggest that you emulate the shell

How to bring a child process running in the background to the foreground

岁酱吖の 提交于 2019-12-02 00:52:28
If I used fork() and execv() to spawn several child processes running in the background and I wanted to bring one of them to the foreground, how could I do that? I am trying to write a shell that can start processes either in the foreground or background. "Background" and "foreground" are not terms used generically for processes, but rather only apply to shells which can wait for jobs on demand. Matt Joiner Complimentarily to Ignacio Vazquez-Abram's answer , I suggest that you emulate the shell foreground/background model. As far as I can tell, backgrounding a process means suspending it. The

How to use execv() without warnings?

痞子三分冷 提交于 2019-11-30 16:07:42
I am working on MacOS-X Lion with GCC 4.2. This code works, but I get a warning I would like fix: #include <unistd.h> main() { char *args[] = {"/bin/ls", "-r", "-t", "-l", (char *) 0 }; execv("/bin/ls", args); } warning: deprecated conversion from string constant to 'char*' I do not want the warning to be suppressed, I want not to have it at all. It is C++ code, not C. Using a char *const (so exactly the type required by execv()) still produces the warning. Thank you. This seems to be ok: #include <unistd.h> main() { char const *args[] = {"/bin/ls", "-r", "-t", "-l", NULL }; execv("/bin/ls",

Writing an interpreter or more like a command prompt program

强颜欢笑 提交于 2019-11-30 09:53:37
问题 I'm supposed to write an interpreter program which is more like a command prompt. This is some background info: General flow of basic interpreter 1. Prompt for user request. 2. Carry out the user request. 3. Unless user terminates the program, go to step 1. Run a command. Format: R command_path [arg1 to arg4] //a single character ‘R’ which stands for 'Run', followed by the path of the command //the user can supply up to 4 command line arguments Behavior: a. If command exist, run the command

Writing an interpreter or more like a command prompt program

会有一股神秘感。 提交于 2019-11-29 18:13:34
I'm supposed to write an interpreter program which is more like a command prompt. This is some background info: General flow of basic interpreter 1. Prompt for user request. 2. Carry out the user request. 3. Unless user terminates the program, go to step 1. Run a command. Format: R command_path [arg1 to arg4] //a single character ‘R’ which stands for 'Run', followed by the path of the command //the user can supply up to 4 command line arguments Behavior: a. If command exist, run the command in a child process with the supplied command line arguments  Wait until the child process is done b.

How to make gdb follow execv? Not working despite “follow-exec-mode”

和自甴很熟 提交于 2019-11-29 10:10:31
i've written two simple programs: int main(int ac, char **argv ) { execv( "/home/me/Desktop/execvtest2", argv ); } and int main(int ac, char **argv ) { execv( "/home/me/Desktop/execvtest1", argv ); } I've compiled them with gcc -g to the according outputfiles. I'm running Ubuntu 10.10 using gcc (Ubuntu/Linaro 4.4.4-14ubuntu5.1) 4.4.5. When I'm debuging the first program with GNU gdb (GDB) 7.2-ubuntu, I can step until the first execv statement, but then the two files just keep running. Even if I set the follow-exec-mode to new, I can't step into the second program. When I set catch exec, gdb

How to inherit stdin and stdout in python by using os.execv()

放肆的年华 提交于 2019-11-28 14:04:48
First, I wrote a c++ code as follows: #include <cstdio> int main() { int a,b; while(scanf("%d %d",&a,&b) == 2) printf("%d\n",a+b); return 0; } I use g++ -o a a.cpp to complie it. Afterwards, I wrote python code as follows: import os,sys sys.stdin = open("./data.in","r") sys.stdout = open("./data.out","w") pid = os.fork() if pid == 0: cmd = ["./a","./a"] os.execv(cmd[0],cmd) However, the data.out file contains nothing. That is to say, the child process did not inherit stdin and stdout from his parent process. But when I wrote a c++ code as follows: #include<unistd.h> #include<cstdio> int main()

Pointer losing its value + execv compilation warning

梦想与她 提交于 2019-11-27 16:28:37
I hope I haven't missed a similar question. I'm trying to code a mini-shell of my own, using primitive C functions. I got something that should work, but I have a pointer that makes everything bug. My adrCmd pointer should get the command-path string from the searchCmd() function and keep the same value in the main function. In fact: it points to the right value on searchCmd() , but not in the main() . Here's the code: int searchCmd(char* cmd, char* adrCmd){ char* path = getenv("PATH"); if(debug)printf("PATH : %s\n", path); int nbPath = (compteLettre(path, ':')+1); char** pathTab = malloc