LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-30-2010, 04:33 AM   #1
aarsh
Member
 
Registered: Mar 2010
Location: USA
Distribution: Ubuntu MATE
Posts: 182

Rep: Reputation: 18
Question a simple download schedular (self made)


I have created a simple download schedular with source-code give below :

---------------------record_strokes.sh-------------------

touch /home/student/packs/lynx/logfile

lynx -cmd_log /home/student/packs/lynx/logfile

---------------------play_strokes.sh---------------------
lynx -cmd_script='/home/admin/packs/lynx/logfile' www.google.com


--------------------download_links.sh---------------------
wget http://iso.linuxquestions.org/downlo...i386-disc1.iso

wget http://iso.linuxquestions.org/downlo...i386-disc2.iso

wget http://iso.linuxquestions.org/downlo...i386-disc3.iso




--------------------halt.sh---------------------
halt


--------------------main.c---------------------

#include<stdio.h>
//#include<sys/ipc.h>
//#include<sys/shm.h>
//#include<sys/types.h>
//#include<sys/sem.h>
#include<pthread.h>

void download(void)
{
system("sh download_links.sh");
}
main()
{
pthread_t id1,id2;
system("sh record_strokes.sh");
system("sh play_strokes.sh");
pthread_create(&id1,NULL,download,NULL); // Error in 3rd para.
pthread_create(&id2,NULL,download,NULL); // Error in 3rd para.
pthread_exit(NULL);
system("sh halt.sh");
return 0;
}


So, this is a simple download scheduler program code. Which creates multiple threads of the downloading process - wget (i could also have used 'curl' instead 'wget').Can you debug this code?
Can anyone guide me please?
 
Old 04-30-2010, 04:54 AM   #2
broken
Member
 
Registered: Apr 2010
Location: Your mom's trailer
Distribution: NetBSD
Posts: 31

Rep: Reputation: 15
From `man pthread_create`:

Code:
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
Thus, your "download" function should have the following signature:

Code:
void *download(void *)
P.S.: You created 4 identical threads and still failed to post in the correct sub-forum. Good job.

Last edited by broken; 04-30-2010 at 05:01 AM.
 
Old 04-30-2010, 06:49 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Reporting and closing duplicates---keep this one
 
Old 04-30-2010, 08:12 AM   #4
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
And moving to Programming
 
Old 05-01-2010, 02:20 AM   #5
aarsh
Member
 
Registered: Mar 2010
Location: USA
Distribution: Ubuntu MATE
Posts: 182

Original Poster
Rep: Reputation: 18
@ broken :

Doing so gives an error :


main.c:8: error: parameter name omitted
 
Old 05-01-2010, 03:29 AM   #6
broken
Member
 
Registered: Apr 2010
Location: Your mom's trailer
Distribution: NetBSD
Posts: 31

Rep: Reputation: 15
Try reading a good book on C programming before attempting to program in C.
 
Old 05-01-2010, 04:42 AM   #7
aarsh
Member
 
Registered: Mar 2010
Location: USA
Distribution: Ubuntu MATE
Posts: 182

Original Poster
Rep: Reputation: 18
just : void *download() solved the issue !!
 
Old 05-01-2010, 09:49 AM   #8
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by aarsh View Post
just : void *download() solved the issue !!
Have you ever tried to compile with '-Wall -Wextra' ?
 
Old 05-04-2010, 02:45 AM   #9
aarsh
Member
 
Registered: Mar 2010
Location: USA
Distribution: Ubuntu MATE
Posts: 182

Original Poster
Rep: Reputation: 18
Question

Quote:
Originally Posted by Sergei Steshenko View Post
Have you ever tried to compile with '-Wall -Wextra' ?
what is this? I don't about such a word at all ?
 
Old 05-04-2010, 02:56 AM   #10
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by aarsh
what is this? I don't about such a word at all ?
See below:
http://gcc.gnu.org/onlinedocs/gcc/Wa...arning-Options
 
Old 05-04-2010, 12:27 PM   #11
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 110Reputation: 110
Just an fyi, the following is considered bad form:
Code:
system("sh download_links.sh");
as compared with:

Code:
system("/bin/sh /home/user/.download/download_links.sh");
It is left as an exercise for the reader to understand why explicit paths are better than searching the user path when executing code "under-the-hood".
 
  


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
[SOLVED] a simple download schedular (self made) aarsh Linux - Networking 1 04-30-2010 05:53 AM
a simple download schedular (self made) aarsh Linux - Newbie 1 04-30-2010 05:52 AM
a simple download schedular aarsh Linux - Software 1 04-30-2010 05:49 AM
LXer: Symfony Made Simple LXer Syndicated Linux News 0 07-11-2007 05:48 PM
Boot Loader -made simple ? pacer Red Hat 4 11-08-2004 12:37 PM

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

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