execvp

usage of pseudo terminal — C

白昼怎懂夜的黑 提交于 2019-12-06 15:00:06
问题 I created a pThread with a specific session number. If the pThread is spawned I try to get another process running the pseudo terminal launched using openpty . Here is some part of the code: if (openpty(&(numa_pst[session][0]),&(numa_pst[session][1]), NULL, NULL, NULL) != 0) { int err_code = errno; sprintf (line_temp, "*** ERROR: numa openpty failed with:\n%s\n", strerror(err_code)); } session = 0; int* pi = calloc(sizeof(int), 1); *pi = session; if (pthread_create(&system_wideThread[session]

C++, linux, fork, execvp, waitpid and SIGTSP

萝らか妹 提交于 2019-12-06 13:25:31
I'm implementing a Terminal for a Home Work. I almost finished, I just need to implement a bg ( Background ) and a fg ( Foreground ) commands. my code looks like this: void run(){ string command[] = parseMyInput( getInput() ); int fork_result = fork(); if( -1 == fork_result ) //handle error else if( 0 == fork_result ){ // child setpgrp(); // I don't want the children to get the signals if( -1 == execvp( command[0], makeArgs(command) ) ) //handle error } else { // parent if( command[ length - 1 ] != "&" ){ int status; waitpid( fork_result, &status, 0 ); //continue after child is finished //(

Handling arguments array of execvp?

此生再无相见时 提交于 2019-12-04 22:49:32
问题 When I call execvp , for example execvp(echo, b) where b is an array of arguments for the command a, will changing this array later affect the execvp call made previously? When I try calling execp(echo, b), it ends up printing out (null) instead of the content inside of b. Can anyone point out why and what I have to do to pass the arguments correctly? 回答1: After you call exec() or one if its relatives, your original program doesn't exist anymore. That means nothing in that program can affect

usage of pseudo terminal — C

≯℡__Kan透↙ 提交于 2019-12-04 21:02:33
I created a pThread with a specific session number. If the pThread is spawned I try to get another process running the pseudo terminal launched using openpty . Here is some part of the code: if (openpty(&(numa_pst[session][0]),&(numa_pst[session][1]), NULL, NULL, NULL) != 0) { int err_code = errno; sprintf (line_temp, "*** ERROR: numa openpty failed with:\n%s\n", strerror(err_code)); } session = 0; int* pi = calloc(sizeof(int), 1); *pi = session; if (pthread_create(&system_wideThread[session], 0, system_wider, (void*)pi)) { int err_code = errno; sprintf (line_temp, "*** ERROR: System-wide

Why is argv parameter to execvp not const?

a 夏天 提交于 2019-12-03 11:42:24
问题 execvp is defined thus: int execvp(const char *file, char *const argv[]); Which precludes code such as this from being used: const char* argv[] = {"/bin/my", "command", "here", NULL}; execvp(argv[0], argv); Was this an accidental omission? Is it safe to const_cast around this? Or do some execvp implementations actually scribble on that memory? 回答1: The POSIX spec says (http://pubs.opengroup.org/onlinepubs/009604499/functions/exec.html): The argv[] and envp[] arrays of pointers and the strings

execvp/fork — how to catch unsuccessful executions?

拜拜、爱过 提交于 2019-12-03 01:36:42
Right now I'm writing a C program that must execute a child process. I'm not doing multiple child processes simultaneously or anything, so this is fairly straightforward. I am definitely executing the built-in shell programs (i.e. things like cat and echo) successfully, but I also need to be able to tell when one of these programs fails to execute successfully. I'm trying this with the following simplified code: int returnStatus; // The return status of the child process. pid_t pid = fork(); if (pid == -1) // error with forking. { // Not really important for this question. } else if (pid == 0)

Why is argv parameter to execvp not const?

不问归期 提交于 2019-12-03 01:15:50
execvp is defined thus: int execvp(const char *file, char *const argv[]); Which precludes code such as this from being used: const char* argv[] = {"/bin/my", "command", "here", NULL}; execvp(argv[0], argv); Was this an accidental omission? Is it safe to const_cast around this? Or do some execvp implementations actually scribble on that memory? The POSIX spec says ( http://pubs.opengroup.org/onlinepubs/009604499/functions/exec.html ): The argv[] and envp[] arrays of pointers and the strings to which those arrays point shall not be modified by a call to one of the exec functions, except as a

Trying to understand how execvp works

眉间皱痕 提交于 2019-12-02 20:16:04
问题 I found so many explanations and answers on execvp but it all seems confusing. execvp takes a command and sends it to kernel and then does something, execvp creates an image, execvp is system call, execvp ...etc. As a beginner with limited C language and Linux experience, only the following explanation seemed to click for me: It's executing ls with 2 arguments: > and awd.txt . It is equivalent to running: 'ls' '>' 'awd.txt' Here is the thread: What does execvp actually do? However, I asked

How to get error of execvp in the fork()?

不问归期 提交于 2019-12-02 15:22:05
问题 I have the following code. My question is in the code int main() { .... if ((uproc.pid = fork()) == -1) { return -1; } if (uproc.pid == 0) { /* child */ const char *argv[3]; int i = 0; argv[i++] = "/bin/sh"; argv[i++] = "/my/script.sh"; argv[i++] = NULL; execvp(argv[0], (char **) argv); exit(ESRCH); } else if (uproc.pid < 0) return -1; /* parent */ int status; while (wait(&status) != uproc.pid) { DD(DEBUG,"waiting for child to exit"); } // If /my/script.sh exit accidentally in some place with

Trying to understand how execvp works

ぐ巨炮叔叔 提交于 2019-12-02 07:39:52
I found so many explanations and answers on execvp but it all seems confusing. execvp takes a command and sends it to kernel and then does something, execvp creates an image, execvp is system call, execvp ...etc. As a beginner with limited C language and Linux experience, only the following explanation seemed to click for me: It's executing ls with 2 arguments: > and awd.txt . It is equivalent to running: 'ls' '>' 'awd.txt' Here is the thread: What does execvp actually do? However, I asked the following question to the person who answered and he did not reply, hence I'm asking separately in a