LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-05-2014, 03:15 PM   #1
one girl
LQ Newbie
 
Registered: Apr 2014
Posts: 20

Rep: Reputation: Disabled
Exclamation help me to Understanding Complex function (Explain Plz)


I Found some Useful function
but I want to Understand it so I can do something like it


Code:


Last edited by one girl; 05-05-2014 at 04:59 PM.
 
Old 05-05-2014, 03:32 PM   #2
cin_
Member
 
Registered: Dec 2010
Posts: 281

Rep: Reputation: 24
what parts of the code is confusing to you?

what parts do you already understand?

the long short is you are creating a custom shell environment where you accept user input, then send that input to be tokenised, or broken into pieces, then send the tokens to the execute function to spawn child processes based on the tokens.

shell runs
..accepts input
..sends input to parse
....parse tokenises input
..shell sends tokens to execute function
....execute runs tokens and informs of error if failure occurs

Last edited by cin_; 05-05-2014 at 03:43 PM. Reason: gramm`err
 
Old 05-05-2014, 03:36 PM   #3
one girl
LQ Newbie
 
Registered: Apr 2014
Posts: 20

Original Poster
Rep: Reputation: Disabled
Actually we didn't understand any thing
But the important thing it's working as our teacher want


But the worst thing in the world
We have to explain it to here
 
Old 05-05-2014, 03:46 PM   #4
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
first
Quote:
(Explain Plz)
the word PLEASE is NOT spelled as "plz"
-- the nun's will smack your knuckles with a ruler for that

also this is NOT a 140 character SMS text message
so PLEASE!!!!!!! do not use "text speak"
 
Old 05-05-2014, 03:49 PM   #5
one girl
LQ Newbie
 
Registered: Apr 2014
Posts: 20

Original Poster
Rep: Reputation: Disabled
Ok ok I will write it " please"
I am not that much good in English language
I didn't know this is wrong to write it like this

Anyhow , what about the function above :'(
 
Old 05-05-2014, 03:52 PM   #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 one girl View Post
Actually we didn't understand any thing
But the important thing it's working as our teacher want


But the worst thing in the world
We have to explain it to here
Your job is to tell the teacher how it works.

Your question to us is "How does it work?"

How do you expect us to answer you without doing your work for you?

Last edited by dugan; 05-05-2014 at 03:55 PM.
 
Old 05-05-2014, 03:53 PM   #7
cin_
Member
 
Registered: Dec 2010
Posts: 281

Rep: Reputation: 24
teachers and textbooks

if the teacher and textbook are of little help then the only recourse is to tinker

here is what you do...
take your code base,
compile it,
and run it with a series of different inputs

then go back to the code base and change one thing in it that you are having a hard time understanding, only one thing at a time and only slightly so that you can recognise and keep track of the changes,
then recompile and send the same series of inputs

try changing
Code:
 printf("shell~ ");
to
Code:
 printf("my lovely shell :) ");
how did the output change? what can you now infer about the code from seeing these changes?

if a change completely breaks the program then search for error codes online
for instance looking at this potentially confusing line:
Code:
arg = strtok(NULL, " \t\n");
if i change strtok to strtik, the program fails.. better investigate..
now i know somewords followed immediately by a parenthesis signals a function call, but the function is vacant from the code, so maybe it is built into the system... searching:
https://www.google.com/search?q=strtok
lands me here:
http://www.cplusplus.com/reference/cstring/strtok/
this explains clearly what strtok does, what arguments it takes and what kind of activity i should expect when i run it
do this for every bit you find confusing
move line by line

now with your new knowledge go back to the original code base and change something else,
repeat

Last edited by cin_; 05-05-2014 at 04:06 PM. Reason: gramm`err
 
Old 05-05-2014, 04:02 PM   #8
one girl
LQ Newbie
 
Registered: Apr 2014
Posts: 20

Original Poster
Rep: Reputation: Disabled
Noooo, the problem not that much worst
Sure I know what the purpose of the code
It will print the shall comment from inside that program
The last function which there name shall
Will print it by using first two function
And I know the concept
But we not understand the parent and child and this thing in first function

Last edited by one girl; 05-05-2014 at 04:03 PM.
 
Old 05-05-2014, 04:19 PM   #9
cin_
Member
 
Registered: Dec 2010
Posts: 281

Rep: Reputation: 24
re`search

what did i suggest?
search terms that are unfamiliar to you until all terms are familiar

https://www.google.com/search?q=chil...+process+linux ::
http://en.wikipedia.org/wiki/Child_process
http://www.lynuxworks.com/products/posix/fork.php3

https://www.google.com/search?q=fork ::
http://linux.die.net/man/2/fork
http://www.cplusplus.com/forum/unices/14125/

Last edited by cin_; 05-05-2014 at 04:19 PM. Reason: gramm`err
 
Old 05-05-2014, 04:36 PM   #10
one girl
LQ Newbie
 
Registered: Apr 2014
Posts: 20

Original Poster
Rep: Reputation: Disabled
if (argv[0] != NULL && strlen(argv[0]) == 4 && strncmp(argv[0], "exit", 4) == 0)

And


char line[1024];

And


char* argv[64] = {NULL};



Thank u cin

What this line means
 
Old 05-05-2014, 04:55 PM   #11
cin_
Member
 
Registered: Dec 2010
Posts: 281

Rep: Reputation: 24
learning how to learn

https://www.google.com/search?q=cplu...%5B1024%5D&rlz

https://www.google.com/search?q=cplusplus+char+line

https://www.google.com/search?q=cplusplus+char

any of these have results that helped you?

Last edited by cin_; 05-05-2014 at 04:56 PM. Reason: gramm`err
 
Old 05-05-2014, 04:58 PM   #12
one girl
LQ Newbie
 
Registered: Apr 2014
Posts: 20

Original Poster
Rep: Reputation: Disabled
Thank u
I will try to understand from those references
 
Old 05-06-2014, 02:29 AM   #13
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Is it just me or has the original code been removed??
 
Old 05-06-2014, 02:48 AM   #14
one girl
LQ Newbie
 
Registered: Apr 2014
Posts: 20

Original Poster
Rep: Reputation: Disabled
Actually this is function inside the code
There is no other function
But I csn not putting it complete now
Any how inshAlla I will try to understand it
Thank u all
 
Old 05-06-2014, 08:46 AM   #15
cin_
Member
 
Registered: Dec 2010
Posts: 281

Rep: Reputation: 24
grail, yes, the original post was edited and the code removed.. unsure why exactly

Last edited by cin_; 05-06-2014 at 08:46 AM. Reason: gramm`err
 
  


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
plz explain about chown.. loba09 Linux - Newbie 3 10-25-2009 05:12 PM
acer fancontrol plz explain majingohan99 Linux - Laptop and Netbook 30 01-22-2009 01:40 PM
explain me this c code plz alaios Programming 1 06-03-2005 05:32 AM
explain this little script plz nukeu666 Linux - Newbie 4 08-18-2004 12:52 AM
can someone explain this error plz? santasballz Linux - Newbie 5 02-10-2004 01:18 PM

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

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