LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-11-2008, 07:15 AM   #1
raedbenz
Member
 
Registered: Dec 2007
Posts: 93

Rep: Reputation: 15
POSIX resources recommendations?


Hi,,,
I am trying to learn writing code in user-space similar to the one below, using POSIX, but in addition to it to use an interrupt. this code will print "Hello World" each certain time. (I found this code in forum).
How can i learn programming using POSIX?
Are there any books recommended? or tutorials?
thanks
Code:
void my_handler
( timer_t timerid,
int myarg );

void start_timer(void)
{
timer_t timerid;
struct itimerspec value;
value.it_value.tv_sec = 5;
value.it_value.tv_nsec = 0;
value.it_interval.tv_sec = 5;
value.it_interval.tv_nsec = 0;
timer_create (CLOCK_REALTIME, NULL, &timerid);
timer_connect (timerid, my_handler,0);
timer_settime (timerid, 0, &value, NULL);
}
void my_handler
( timer_t timerid,
int myarg )
{
printf("\nHello World\n");
}
 
Old 07-11-2008, 10:55 AM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
You should get yourself a copy of Advanced Programming in the UNIX Environment, 2nd Edition, by W. Richard Stevens and Stephen Rago. It is a giant book, but a great reference for POSIX programming and it highlights some of the differences you might run into between different implementations.
 
Old 07-12-2008, 04:52 AM   #3
raedbenz
Member
 
Registered: Dec 2007
Posts: 93

Original Poster
Rep: Reputation: 15
HI,
thanks it seems to be excellent reference.
could u plz clarify to me the difference (if there is) between POSIX we use in Liunx like timer_create(), clock_get_time(), etc...
and POSIX thread (by using <pthread.h> in Unix systems) ?
thanks
 
Old 07-12-2008, 05:16 AM   #4
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
POSIX is the Portable Operating System Interface; you don't "program" in POSIX at all since it is nothing more than a document:

http://www.opengroup.org/austin/papers/posix_faq.html

That FAQ page also has information on how to get a (free) copy of the standards document. I can't say I'd recommend reading it because it will probably only confuse you more.

Don't worry too much about POSIX compliance; there are parts that are not well-specified and often the poor specification is deliberate. However, because of the abundance of poorly defined specifications, writing a 100% POSIX compliant program doesn't mean you have a 100% portable program. As you read manual pages for various libc calls, you'll see comments like "BSD behaves THIS way, Solaris behaves THAT way, and GNU does things this other way". The most annoying differences occur where the specification doesn't explicitly state what arguments may be altered by the procedure, leading to cases where your code works fine on one operating system or with one set of C libraries, and corrupts data on other systems or when other C libraries are used.
 
Old 07-12-2008, 05:29 AM   #5
raedbenz
Member
 
Registered: Dec 2007
Posts: 93

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by pinniped View Post
Don't worry too much about POSIX compliance; there are parts that are not well-specified and often the poor specification is deliberate.
hi,
actually if u look to the code above. i have started analyzing it, (I am now learning how to use POSIX functions), the function "timer_connect()" is not found in any Linux manual pages, on the contrary i found it in VxWorks manual pages. Do u think it is going to work in Linux?

One more thing please:
the code above needs to add to it the <time.h>, <signal.h> and <stdio.h> headers.
Q1. do i need to put the "int main(int argcc, char argv[])" function or just ""void main() ?
Q2. how do u compile such code in Linux? is it like other C code by typing :

$ gcc -o test test.c


Thanks
 
Old 07-13-2008, 12:21 AM   #6
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Quote:
Originally Posted by raedbenz View Post
the function "timer_connect()" is not found in any Linux manual pages, on the contrary i found it in VxWorks manual pages. Do u think it is going to work in Linux?

Q1. do i need to put the "int main(int argcc, char argv[])" function or just ""void main() ?
Q2. how do u compile such code in Linux? is it like other C code by typing :

$ gcc -o test test.c
If timer_connect is not in the GNU libc manual (assuming you're using GNU libc) then the call does not exist. You can always grep through the system and library headers: fgrep -r "timer_connect" /usr/include One thing about POSIX is that you're not required to implement all procedures, so different systems or C libraries conform to different extents. For example, Microsoft claims that WinDuhs and their C compiler are POSIX compliant but most people have learned to ignore MS's claims.

You can still declare main as "void main()"; declaring with 'argc' and 'argv' is only useful if you will be parsing the command line for arguments. Also, you got 'argv' wrong - that should be "char *argv[]" or else "char **argv".
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
POSIX Barrier?? MeMooMeM Programming 5 05-26-2005 02:19 PM
About POSIX threads Ephracis Programming 1 12-03-2004 06:33 AM
Posix arunshivanandan General 1 05-19-2003 08:07 AM
Posix? justiceisblind Linux - Newbie 2 03-11-2002 08:04 PM
posix thread sulo Programming 1 02-28-2002 07:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration