0

So I want to create a process and keep it running for a certain amount of time, before calling SIGINT on it and killing it.

So what I have done is created a struct pcb (process control block), and when I have this process running i set

mypcb->status = RUN //RUN would just be defined as 0, SUSPEND as 1, etc

Basically I have a function that manages all my processes, and I might have in this function something like

startprocess(processnum);
wait 10 seconds
killprocess(processnum);

So then in my startprocess function I call fork, and in the child process (when fork() == 0), I want to keep this process running indefinitely. I know this can probably be done by using execvp, but I don't want to switch context to another exe file, I just want to keep the process running, or at least make it seem like the child process is still alive so that I can go back and call SIGINT on the pid in my killprocess function.

Note that I store the pid of each process in

mypcb->pid

so i dont need to pass anything, I just need a way to keep the process running so I can go back and kill it after.

Hopefully my question makes sense, basically I just want to know how I can keep a process running without it doing anything, so that I can kill it later.

Thanks!

Steven Hsu
  • 183
  • 1
  • 3
  • 15

1 Answers1

0

It sounds like all you're trying to do is make a process run forever doing nothing in particular (and in that case the rest of the question is irrelevant).

You can simply use something like:

while(1)
{
    /* no code in between the {} */
}

which will do nothing, forever.

user253751
  • 57,427
  • 7
  • 48
  • 90
  • 1
    actually, to avoid the process being a cpu resource hog, the interior of that while loop should probably make a call to usleep() or nanosleep() – user3629249 Apr 11 '15 at 12:15