C system() function

This is a discussion on C system() function within the Linux Programming forums, part of the Platform Specific Boards category; I know windows uses the pause system call to wait for a keypress on stdin i.e. system("pause");. is there an ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    13

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,489
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    I agree with Salem, but if you need it all you have to do is
    Code:
    #include <unistd.h>
    /*code*/
    pause();
    it always returns -1 so you don't really need to get its return value. This has been replaced though, with sigsuspend();
    Code:
    #include <signal.h>
    /*code*/
    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
    [sources]
    sigsuspend example
    man pause
    man sigsuspend
    [/sources]

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    13
    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, 02: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, 04: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21