473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

nanosleep mystery

Hi,
I executed the following code on slackware 10.2 (with 2.6.22 kernel)
and ubuntu 7.10 (again with 2.6.22 kernel).
On slackware, the value of "diff" is sometimes 0(zero). On ubuntu it
is consistently above 1(one). Can anybody tell me why this may be
happening??

/***************** Code listing ****************************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/times.h>

int main(int argc, char *argv[])
{
clock_t t1, t2, diff;
struct timespec req_time, rem_time;

req_time.tv_sec = 0;
req_time.tv_nsec = atol(argv[1]);

do {
if ((t1 = times(NULL)) == (clock_t)(-1)) {
perror("times");
exit(1);
}

if (nanosleep(&req_time, &rem_time) == -1) {
perror("nanosleep");
exit(1);
}

if ((t2 = times(NULL)) == (clock_t)(-1)) {
perror("times");
exit(1);
}

diff = t2 - t1;

printf("diff = %ld\n", diff);
} while (1);

return 0;
}
Dec 13 '07 #1
3 3396
In article <0e**********************************@s12g2000prg. googlegroups.com>,
chandanlinster <ch************@gmail.comwrote:
>Hi,
I executed the following code on slackware 10.2 (with 2.6.22 kernel)
and ubuntu 7.10 (again with 2.6.22 kernel).
On slackware, the value of "diff" is sometimes 0(zero). On ubuntu it
is consistently above 1(one). Can anybody tell me why this may be
happening??
Off topic, blah, blah, blah.

We all know the drill by now.

Dec 13 '07 #2
chandanlinster wrote:
Hi,
I executed the following code on slackware 10.2 (with 2.6.22 kernel)
and ubuntu 7.10 (again with 2.6.22 kernel).
On slackware, the value of "diff" is sometimes 0(zero). On ubuntu it
is consistently above 1(one). Can anybody tell me why this may be
happening??
Ask on a newsgroup related to those operating systems. This is not
something that is actually related to the C language.

As nanosleep is a POSIX function, comp.unix.programmer may be a suitable
place to raise the question. Alternatively, as this relates to Linux
systems in particular, one of the Linux newsgroups may be better.
Dec 13 '07 #3
chandanlinster wrote:
>
I executed the following code on slackware 10.2 (with 2.6.22
kernel) and ubuntu 7.10 (again with 2.6.22 kernel). On slackware,
the value of "diff" is sometimes 0(zero). On ubuntu it is
consistently above 1(one). Can anybody tell me why this may be
happening??
.... snip ...
>
printf("diff = %ld\n", diff);
} while (1);

return 0;
}
diff is a clock_t. What does printf desire for a %ld descriptor|?

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Dec 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Red | last post by:
In netscape bookmark files, there are lots of lines like this: <DT><A HREF="http://www.commondreams.org/" ADD_DATE="1091500674" LAST_CHARSET="ISO-8859-1" ID="rdf:#$uiYyb3">Common Dreams</A> I...
12
by: Raymond Hettinger | last post by:
For your amusement and edification, I'm working on a series of Python puzzles designed to highlight areas of the language known only to those who have read the docs more than once. Each of the...
0
by: Francis Avila | last post by:
A few days ago (see the 'itertools.flatten()?' thread from October 28) I became obsessed with refactoring a recursive generator that yielded the leaves of nested iterables. When the dust settled,...
0
by: Morris Carré | last post by:
Back then - in particular, soon after 9/11 - I evidenced the natural irony of the standard python implementation, by showing it had the clear and spontaneous humor of replying : 'BUSH' when...
3
by: Jim Geissman | last post by:
I have function that returns a table of information about properties. The data comes from three different tables -- addresses (called PropertyID), property characteristics, and events concerning...
0
by: William Wisnieski | last post by:
Hello Everyone: I'm having a very strange problem occurring with my Access 2000 database. I call it the "mystery record." Here's the story: I have a query by form that returns a record set...
115
by: Mark Shelor | last post by:
I've encountered a troublesome inconsistency in the C-language Perl extension I've written for CPAN (Digest::SHA). The problem involves the use of a static array within a performance-critical...
14
by: jojoba | last post by:
Hi, I hope this post is ok for this group. Here's my deal: I have two computers on my LAN at home. One desktop. One laptop. Both computers are wireless enabled (and wired enabled too). I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.