简体   繁体   中英

fork() and execvp()

I'm having problems trying to execute a process using fork() and execvp() . I have a struct Pcb which has an array of arguments ( args ):

#define MAXARGS 2

struct pcb {
    pid_t pid;             // system process ID
    char *args[MAXARGS];  // program name and args
    int arrivaltime;
    int remainingcputime;
    struct pcb * next;     // links for Pcb handlers
    int priority, memalloc, res1, res2, res3, res4, status;
};
typedef struct pcb Pcb;
typedef Pcb * PcbPtr;

the first of which is the name of the program to be executed.

And this is my fork function

PcbPtr startPcb(PcbPtr process) {
    int pid;
    switch (pid=fork()) {
        case -1:
            return NULL;
        case 0:
            execvp(process->args[0], process->args);
        default:
            return process;
    }
    process->status = 2;
    return process;
}

Note: process->args[0] is just a const string called "process" which refers to a compiled program called 'process' in the current directory.
There are no arguments.

When I use gdb and follow the child process its just says:

[New process 15186]
[Switching to process 15186]
13                              execvp(process->args[0], process->args);
(gdb)

Program received signal SIGTSTP, Stopped (user).
startPcb (process=0x602250) at util.c:13
13                              execvp(process->args[0], process->args);
(gdb)

Why is it receiving SIGSTP?

原来我没有在args [0]中指定完整路径

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM