Skip site navigation (1)Skip section navigation (2)
Date:        Sun, 24 Jun 2001 23:06:32 +0200
From:      Arjan Knepper <arjan@jak.nl>
To:        fybar <fybar@powersurfr.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: pause in c program
Message-ID:  <3B365658.24824777@jak.nl>
References:  <3B3637D6.ABDB4B0@powersurfr.com>

next in thread | previous in thread | raw e-mail | index | archive | help
fybar wrote:

> I am a newbie programmer running FreeBSD  3.5.1 on my laptop, I have had
>
> more success with this version with pcmcia cards.  Anyhoo, I am writing
> a program that I want to have print out some lines at a certain tempo.
> Is
> there a function that will let me pause the program for a specified
> amount of time?
>
> I tried sleep, but I got some errors during the compile.  Is there a way
>
> to call UNIX commands from a c program?

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

int  main ()
{
...
   char  cmd [ 256 ];

   memset ( cmd, 0, 256 );

   snprintf ( cmd, 255, "some shell command %s", "some parameters" );
   system ( cmd  );    // execute sh-shell fork && execve cmd
...
    sleep ( 1 );           // sleep for a second
    usleep (  1000 );  // sleep for an other ssecond

    return ( 0 );
}

read:
# man system
# man -a 3 sleep
# man -a 3 usleep

Make sure to link against the stdclib:
gcc ... -lc

>
>
> My compiler is gcc 2.7.
>
> --
> fybar@nospam.powersurfr.com
>
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-questions" in the body of the message


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3B365658.24824777>