Thread: C system() function

  1. #1
    Registered User
    Join Date
    Mar 2004

    C system() function

    I know windows uses the pause system call to wait for a keypress on stdin i.e. system("pause");.

    is there an equivelant system call that I can use in linux??

    or will I have to use fgetc();?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Well reading a char from stdin would be the most portable way of doing it.

    Are you absolutely sure you need it. Most windows people just need it to stop the popup DOS box which is created from disappearing again before they can read anything.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    I agree with Salem, but if you need it all you have to do is
    #include <unistd.h>
    it always returns -1 so you don't really need to get its return value. This has been replaced though, with sigsuspend();
    #include <signal.h>
    sigset_t mask, oldmask;
    /* Set up the mask of signals to temporarily block. */ 
    sigemptyset (&mask); 
    sigaddset (&mask, SIGUSR1);
    /* Wait for a signal to arrive. */
    sigprocmask (SIG_BLOCK, &mask, &oldmask);
    while (!usr_interrupt)
      sigsuspend (&oldmask);
    sigprocmask (SIG_UNBLOCK, &mask, NULL);
    A little more confusing but reliable
    sigsuspend example
    man pause
    man sigsuspend

  4. #4
    Registered User
    Join Date
    Mar 2004
    I was recieving a response from a server via sockets. wanted to dispay the responce, then pause, then clear the terminal to restart the program.

    Though now I think about it, clearing the response that the server sends isnt such a good idea is it. lol

    Thanx for your help guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM