0

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?

Andy Hayden
  • 359,921
  • 101
  • 625
  • 535
Milk
  • 647
  • 1
  • 6
  • 18

1 Answers1

1

Turns out I wasn't specifying the full path in args[0]

Milk
  • 647
  • 1
  • 6
  • 18
  • There'd be not much point in using `execvp()` if the `args[0]` value contains a path (anything with a slash `/` in it). Then the PATH can't be used to find it. – Jonathan Leffler Jun 07 '12 at 06:14