LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-22-2008, 07:47 AM   #1
wrapster
Member
 
Registered: May 2008
Posts: 155

Rep: Reputation: 30
newbie to unix programming in C, needed a few simple prgs on these functions!


Hi all,

I am a newbie to unix programming using C..
So i would like to have a few simple C programs to start off with..
I wanted programs on learning ,
abort,kill and raise,alarm and pause,
I would also like to know how to use the vfork()
It would be really great if i can have these programs


Thanks

Last edited by wrapster; 06-22-2008 at 07:59 AM.
 
Old 06-22-2008, 08:18 AM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Play around with 'signal' and 'alarm'. If you're a beginner there's no way you'll understand the actual programs that make use of these. It's better to practice by building your own toy program which does nothing useful but you can make quick changes to make sure you understand what's going on.

man sigaction

Just create signal handlers that print something out as you send different signals (SIGUSR1/2, SIGINT, SIGTERM, SIGPIPE ... etc etc etc).

For 'alarm', you just have to handle 'SIGALRM'.

For 'pause' - similar to 'alarm' - once you have actually implemented signal handlers, it's easy to use.

For 'vfork' do the same - write a small program that does nothing useful but prints out statements to show you that you got things right and can tell the difference between the child and parent process.
 
Old 06-22-2008, 08:40 AM   #3
wrapster
Member
 
Registered: May 2008
Posts: 155

Original Poster
Rep: Reputation: 30
ok ,i will try..
But if you could point me out to some starting material on the web,it would be great

Thanks
 
Old 06-22-2008, 06:00 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Here's a good tutorial: http://www.cs.cf.ac.uk/Dave/C/, specifically http://www.cs.cf.ac.uk/Dave/C/node24...00000000000000

google is your friend...
 
Old 06-23-2008, 02:17 AM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by wrapster View Post
I am a newbie to unix programming using C..
So i would like to have a few simple C programs to start off with..
This free downloadable book may be what you're looking for. Follow the download link to download it as a PDF per chapter and the example code.
 
Old 06-23-2008, 08:29 AM   #6
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
What you are asking about specifically is well covered here.
 
Old 06-26-2008, 03:51 AM   #7
ChipB
LQ Newbie
 
Registered: Oct 2007
Posts: 10

Rep: Reputation: 0
Heres a little sample code:

void print_signal_number(int sig) // not in all_and_everything.h
{
fprintf(stderr,"received sig = %d\n",sig);
}

void init_to_trap_and_print_all_signal_numbers()
{

for(int i=1; i<32; i++) signal(i, print_signal_number);
}

///////////////////////////////
{
.......
quir__signal( 17, quir__signal__nothing); // needed to stop death of child from killing parent
}
int pid = fork();
if ( pid == -1) return pid; // pid= -1 ==> fork failed
if ( pid != 0 ) return pid; // pid= 0 ==> I am parent

.... action of chilkd
}
 
Old 06-29-2008, 01:23 AM   #8
iwasapenguin
Member
 
Registered: Jul 2007
Posts: 110

Rep: Reputation: 15
at the terminal:
man 3 function
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
In UNIX/LINUX, some functions like LoadLibrary and GetProcAddress? chenjifu Programming 3 04-20-2009 02:24 PM
Newbie Q(sorry): Programming simple apps for school... Gregor7777 Programming 2 10-07-2004 10:26 AM
UNIX (Linux, BSD, etc) Programming :: UNIX kuphryn Programming 8 04-04-2004 11:50 PM
newbie: unix network programming: UDP and send file geo_h Programming 3 09-17-2003 11:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:34 PM.

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