Sponsored Content
Full Discussion: Delay a process.
Top Forums Programming Delay a process. Post 101398 by matrixmadhan on Wednesday 8th of March 2006 01:31:48 AM
Old 03-08-2006
introducing a sleep would effect the process,
either it is a foreground or background process

if you are so particular in guaranteeing 3 seconds
use sigALARM for 3 seconds

check for the following code;

Code:
# include<stdio.h>
# include<time.h>

void a();
void b();
void c();

int main()
{
  clock_t c1, c2, c3;
  c1=clock();

  (void)a();

  c2=clock();
  fprintf(stderr, "Diff returning from fun a %ld\n", c2 - c1);
  c1=clock();

  (void)b();

  c2=clock();
  fprintf(stderr, "Diff returning from fun b %ld\n", c2 - c1);
  c1=clock();
  sleep(3);

  (void)c();
  c2=clock();
  fprintf(stderr, "Diff returning from fun c %d\n", c2 - c1);
  return 0;
}

void a()
{
  int i;
  fprintf(stderr, "in a\n");
  for( i=0; i<500000; i++);
}
void b()
{
  int i;
  fprintf(stderr, "in b\n");
  for( i =0; i<200000; i++);
}
void c()
{
  int i;
  fprintf(stderr, "in c\n");
  for( i =0; i<600000; i++);
}

the above code uses clock function and hence only the real time used by the process would be affected the sleep(3) and not the cpu time.
clock function will account only for the CPU and system time and not the context switch to sleep state and hence sleep cannot track the 3 seconds

you need to use the following structure in /usr/include/sys/time.h

Code:
struct tms {
  clock_t  tms_utime;     /* user time */
  clock_t  tms_stime;     /* system time */
  clock_t  tms_cutime;    /* user time, children */
  clock_t  tms_cstime;    /* system time, children */
};

hope this helps!!!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Delay in mv

Working on AIX 4.3 I have an active exe that accepts files for processing on our RS6000. Day to day i store these files in a secure place and at the end of the day I mv them one by one. After some reading and ofcourse trial and error i figured out that this helps... mv `ls -l |head -l | awk... (2 Replies)
Discussion started by: buRst
2 Replies

2. Programming

Introducing Delay less then a second.

Hi, I have a doubt in introducing a delay in the programs. We know that we do have a sleep() function/api using which we can bring a delay in terms of seconds. A minimum delay can be atleast 1 second. Now I'm bothered about how to introduce a delay that is just less than a second. Like... (3 Replies)
Discussion started by: S.Vishwanath
3 Replies

3. Shell Programming and Scripting

while loop and delay

Dear all, if we want to run a command every 5 mins to check if the process is working fine or not... like in c, we can use a simple while loop with a delay for 5 mins... how can we accomplish this is solaris 8/9 thanks br/asad (5 Replies)
Discussion started by: asadlone
5 Replies

4. UNIX for Advanced & Expert Users

how to delay a process getting killed before it completes its work

The problem i am encountering is the process is getting killed before it dispalys the details.The details are displayed using printf.I created a new buffer for printing the details using setvbuf function call instead of output buffer.This is not working.The thing is,killing of the process must be... (1 Reply)
Discussion started by: cijkmysj
1 Replies

5. Programming

how to delay a process from getting killed

We are forking a process B from process A and the process B should display the details it reads from process C(daemon process) continuously. Let us say that the process C sents 100 packets.The process B receives all the 100 packets from the process C before it prints all details of 31... (1 Reply)
Discussion started by: cijkmysj
1 Replies

6. Shell Programming and Scripting

How to delay the process for few seconds

Hi, In my shell script, (as per the requirement), I am creating few files, and the processes are launched parallelly . (by using "&" at the end of the command line). As per the logic, I need to remove these files as well, after creating. But, the problem is, due to parallel processing,... (3 Replies)
Discussion started by: jitendriya.dash
3 Replies

7. Red Hat

Fork wait in background process - large delay

hi all, We are trying to run a process in the background and in the process we call fork ;and wait for the child process to finish .We find that the died = wait(&status); happens after 10 seconds randomly and sometimes completes in time (within 1 sec) This behavior is seen only when the... (0 Replies)
Discussion started by: vishnu.priya
0 Replies

8. Red Hat

Fork wait in background process - large delay

hi all, We are trying to run a process in the background and in the process we call fork ;and wait for the child process to finish .We find that the died = wait(&status); happens after 10 seconds randomly and sometimes completes in time (within 1 sec) This behavior is seen only when the... (1 Reply)
Discussion started by: vishnu.priya
1 Replies

9. Shell Programming and Scripting

Loop without a delay

Hi, I am trying to understand what would happen if ther is a loop without any delay like sleep statement, I feel that would add a lot of load onto the CPU. Trying to understand how the load is reduced by the introduction of sleep(). Thanks and regards Zulfi (3 Replies)
Discussion started by: zulfi123786
3 Replies

10. UNIX for Advanced & Expert Users

Trying to understand the delay

Heyas As you know me, i have scripts for about almost every aspect of my IT life. This time, i'm having issues to figure out why my script to connect to my wifi spots takes so long when started as service. The service file (the after:local-fs.target is for 'home installations'): cat... (3 Replies)
Discussion started by: sea
3 Replies
PAM_FAILDELAY(8)						 Linux-PAM Manual						  PAM_FAILDELAY(8)

NAME
pam_faildelay - Change the delay on failure per-application SYNOPSIS
pam_faildelay.so [debug] [delay=microseconds] DESCRIPTION
pam_faildelay is a PAM module that can be used to set the delay on failure per-application. If no delay is given, pam_faildelay will use the value of FAIL_DELAY from /etc/login.defs. OPTIONS
debug Turns on debugging messages sent to syslog. delay=N Set the delay on failure to N microseconds. MODULE TYPES PROVIDED
Only the auth module type is provided. RETURN VALUES
PAM_IGNORE Delay was successful adjusted. PAM_SYSTEM_ERR The specified delay was not valid. EXAMPLES
The following example will set the delay on failure to 10 seconds: auth optional pam_faildelay.so delay=10000000 SEE ALSO
pam_fail_delay(3), pam.conf(5), pam.d(5), pam(8) AUTHOR
pam_faildelay was written by Darren Tucker <dtucker@zip.com.au>. Linux-PAM Manual 09/19/2013 PAM_FAILDELAY(8)
All times are GMT -4. The time now is 11:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy