LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 08-05-2010, 07:06 AM   #1
moreece
LQ Newbie
 
Registered: Aug 2010
Posts: 2

Rep: Reputation: 0
C programming exercises


Hi people am new to c programming in linux and i came across a couple of questions for a program.if u could please help me do it i'd appreaciate it.

•Write a program that requires the user to input the name of a file as an argument. If the user fails to include one argument it should make use of a thread that handles a signal. The signal handler should tells the user “Incorrect number of arguments and then calls the terminate signal on the process.

•If the numbers of arguments are correct then the program should allocate memory space to the file (5MB) and create a child process that requests the user for a character that it should send to the parent. The child should keep request for data until the user keys in the character O. During each request it should pause for 10 seconds, send the character to the parent and then requesting again for another character.

•The parent should get the character from the child. Do not make the parent wait for the child to finish requesting for data. Make use of pipes to facilitate communication between the parent and the child.

•A second child should be created to read and display data from the file. Make use of any appropriate Inter Process Communication technique to ensure that the second child and the parent do not access the file simultaneously (Mutual exclusion).

Last edited by moreece; 08-05-2010 at 07:55 AM.
 
Old 08-05-2010, 07:12 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by moreece View Post
Hi people am new to c programming in linux and i came across a couple of questions for a program.if u could please help me do it i'd appreaciate it.

•Write a program that requires the user to input the name of a file as an argument. If the user fails to include one argument it should make use of a thread that handles a signal. The signal handler should tells the user “Incorrect number of arguments and then calls the terminate signal on the process.

•If the numbers of arguments are correct then the program should allocate memory space to the file (5MB) and create a child process that requests the user for a character that it should send to the parent. The child should keep request for data until the user keys in the character O. During each request it should pause for 10 seconds, send the character to the parent and then requesting again for another character.

•The parent should get the character from the child. Do not make the parent wait for the child to finish requesting for data. Make use of pipes to facilitate communication between the parent and the child.

•A second child should be created to read and display data from the file. Make use of any appropriate Inter Process Communication technique that we have discussed in class to ensure that the second child and the parent do not access the file simultaneously (Mutual exclusion).
http://www.eng.cam.ac.uk/help/tpl/unix/fork.html
 
Old 08-05-2010, 07:57 AM   #3
moreece
LQ Newbie
 
Registered: Aug 2010
Posts: 2

Original Poster
Rep: Reputation: 0
I was hoping for something more specific.
 
Old 08-05-2010, 08:04 AM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by moreece View Post
Hi people am new to c programming in linux and i came across a couple of questions for a program.if u could please help me do it i'd appreaciate it.
That does a good job of making the directly pasted in homework assignment sound like it is not a homework assignment. But the point of the forum rule "don't expect us to do your homework" still applies even if this were self study "homework" you selected on your own.

Do not post just the text of a homework question and ask someone to do (or even start) the whole task for you.

Make an attempt to do it yourself.

Ask specific questions about specific parts of the task that you find difficult.
 
Old 08-05-2010, 08:06 AM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by moreece View Post
I was hoping for something more specific.
Oh, I was hoping to see some code of yours.
 
1 members found this post helpful.
Old 08-05-2010, 08:18 AM   #6
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by moreece View Post
I was hoping for something more specific.
Then ask more specific questions. For example, you could have asked one of the following:
  • please recommend some tutorials on using pipes for IPC
  • here's a function I wrote, here's what it should do, here's what it currently does instead

(No, we're not going to write the code for you, if that's what you mean by "help" and "something more specific.")

Last edited by dugan; 08-05-2010 at 10:50 AM.
 
  


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
Exercises Ace Blackwell Programming 2 08-25-2008 11:37 AM
Making beginner-level programming exercises more interesting and more motivating rm_-rf_windows Programming 14 07-12-2007 07:08 AM
Java Exercises itd_pac Programming 1 08-14-2006 08:27 AM
exercises for learning c... Sky Programming 25 07-18-2002 01:33 AM

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

All times are GMT -5. The time now is 05:05 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