# Tutorials for FreeBSD system programming?



## helmet1080 (Mar 10, 2019)

If I read The Linux Programming Interface, is it OK? I has a couple of chapters on System V... The man page is too hard to learn how to program in this environment, and I don't know how to use it.
man 3 strlen ? I need a guide to follow, to learn everything no idea what exist and how to search it. I've never programmed anything, nothing like system programming before, and in reallity I don't have much time programming. I know The C Programming Language, and I want to learn kernel programming. A friendly and complete guide  on how to use system calls, and how the system works would be ideal. Thanks.


----------



## SirDice (Mar 11, 2019)

You never programmed anything yet you want to learn something as complex as a kernel? Maybe, just maybe, you should start at the beginning? If you don't know the basics something as complex as a kernel will be totally over your head. 



helmet1080 said:


> A friendly and complete guide on how to use system calls, and how the system works would be ideal.


This has nothing to do with kernel programming. The example you gave regarding strlen(3) has nothing to do with the kernel either. Those are standard C library functions. 






						C standard library - Wikipedia
					






					en.wikipedia.org


----------



## Minbari (Mar 11, 2019)

The GNU C Reference Manual
The GNU C Programming Tutorial


----------



## tommiie (Mar 11, 2019)

Hey helmet1080: I agree with SirDice. Can you explain the project you want to start? There are big differences between programming an application or a kernel. When programming an application, there are again quite some differences: will it be a CLI program like cat(1) or grep(1) (i.e. with a real UI) or will it be a program needing CLI windows (i.e. require ncurses(3)? Will it be a GUI application running on KDE, gnome...?

The more we know about your goal (project) the better we can assist in providing a tutorial, book, or other starting point.


----------



## ProphetOfDoom (Mar 11, 2019)

Agreed. I wouldnt attempt kernel programming and I've been programming since I was six.
Good first projects are like... a command line program where the computer selects a number and the user has to guess it... Or maybe a program to print out the multiplication tables from 2 to 12.
Dull maybe but necessary.


----------



## helmet1080 (Mar 11, 2019)

SirDice said:


> You never programmed anything yet you want to learn something as complex as a kernel? Maybe, just maybe, you should start at the beginning? If you don't know the basics something as complex as a kernel will be totally over your head.
> 
> 
> This has nothing to do with kernel programming. The example you gave regarding strlen(3) has nothing to do with the kernel either. Those are standard C library functions.
> ...


I mean I've only copied the snippets that appear on books for C programming. I've programmed a couple of data-structures like linked list, stack, queue, binary tree. I was reading Advanced Programming in the UNIX Environment, 3rd Edition, and  I'm on chapter 4, and  I understand very well what it says. But don't know if I should read/take a course in operating systems like Operating System Concepts 10th Edition by Abraham Silberschatz then any course on operating systems. Maybe I should follow the guide 
	

	




						C standard library - Wikipedia
					






					en.wikipedia.org
				



  and then ask again. Thank you for the reply.



Minbari said:


> The GNU C Reference Manual
> The GNU C Programming Tutorial


The GNU reference manual. I've read that FreeBSD doesn't use the GNUlibrary, uses libc that is a different library. Thank you for the reply.



tommiie said:


> Hey helmet1080: I agree with SirDice. Can you explain the project you want to start? There are big differences between programming an application or a kernel. When programming an application, there are again quite some differences: will it be a CLI program like cat(1) or grep(1) (i.e. with a real UI) or will it be a program needing CLI windows (i.e. require ncurses(3)? Will it be a GUI application running on KDE, gnome...?
> 
> The more we know about your goal (project) the better we can assist in providing a tutorial, book, or other starting point.


Not sure about what project goal to have in mind. But my goal could be to stay envolved, to particapate, to learn anything related to the inner working of the oparing system, and the kernel seems very good place to stay. I'd like to program drivers, I like the kernel, I like the desktop manager KDE Plasma, I like Unix. It's deficult to know where to start if you don't what exists, but for now kernel.
Thank you for the reply.



AlexanderProphet said:


> Agreed. I wouldnt attempt kernel programming and I've been programming since I was six.
> Good first projects are like... a command line program where the computer selects a number and the user has to guess it... Or maybe a program to print out the multiplication tables from 2 to 12.
> Dull maybe but necessary.



I've been reading about python the basics as well, but I like, I prefer compiled programming languages like C. Thank you for the reply.


----------



## helmet1080 (Mar 11, 2019)

pyret said:


> "Advanced Programming in the UNIX Environment" and "UNIX Network Programming" by the late W. Richard Stevens which you're already reading.
> 
> If you want a really good book on operating systems, there is Operating Systems: Three Easy Pieces which is free and used at the University of Wisconsin.  It explains the concepts and has code snippets, but not full code of any operating system.
> 
> ...


Thank you for the reply. What order should read them all in? Yes, they're all interesting to me.  The book: Operating System Design: The XINU Approach. is the one that teaches you how an OS works, and how to build an OS from the ground up, which makes it the coolest book. What are the prerequisites to read this book? I'm interesting in Minix as well, and I wanna learn it. I read it's a Unix-like and it's a POSIX compliant. I have all day to have a tones of fun, so I wanna learn everything I need. Thank you again.


----------



## helmet1080 (Mar 12, 2019)

pyret said:


> I have worked as a UNIX system administrator for 25 years, with AIX, Solaris, and Linux (I do not like it).  I've worked for one of the world's largest online retailers, the largest online stock trader, US DoD, among other companies, and am presently working for the world's largest transportation company.
> 
> But I don't consider myself an expert.  To me, people like Adrian Cockroft, currently the Cloud architect at Amazon AWS and authored "Sun Performance and Tuning: SPARC & Solaris."  Richard McDougall co-authored "Solaris Internals" while at Sun Microsystems and was CTO at VMWare and is currently in Cloud & Infrastructure Engineering at Google.  Or "Solaris Internals" other co-author, Jim Mauro who is currently a performance engineer at NVIDIA.  Another is Bryan Cantrill who was a former Sun Microsystems kernel developer and creator of DTrace, and is now the CTO at Joyent; who also contributes code for SmartOS periodically.  Those are experts.
> 
> ...


I try to apply, use, all the time everything, to really learn. By using "often" what is learned, to get that deeper in my mind. This is a very good method to me. Thank you for the information and advice sir.


----------



## ralphbsz (Mar 12, 2019)

I would start with Tanenbaum's book.  It is sort of an undergraduate level books for the basics.  Don't bother with Minix as an implementation though.  Then I would go to the Dinosaur Book - the Silberschatz.  It's more advanced, more background and concepts, less practical.  I haven't read Remzi's book, but heard about it second hand.  I also hear that the XINU book is probably the best for hands-on practice with an OS.

The Stevens books are very good, but they are not programming books, nor kernel books.  They are excellent concept and reference books for parts of the programming interface: how to use it, not how it is implemented.

Reading C library reference manuals or Gnu documentation won't help at all.  This is reference documentation, which you read when you are debugging a problem.

You claim to know the C language.  How many ten thousand lines of C have you written, which went into production, ran bug-free and which were reviewed by colleagues?

For learning how a real-world kernel works, I don't think there is a better book than the daemon book: Design and Implementation of BSD, by McKusick and friends.  Get it, and read it 10 times.  Try to get your copy autographed by Kirk (mine isn't, which really annoys me).

But all that will not make you a kernel programmer.  Programming in the kernel requires first considerable C programming experience, and then a lot of special attention and care.  If you are serious about it, and have met the preconditions, then download the source, and start improving something random.  For example, find bugs on the FreeBSD bug tracking system, and fix them.


----------



## helmet1080 (Mar 12, 2019)

ralphbsz said:


> I would start with Tanenbaum's book.


Me too. If it's more easier, I'll enjoy for sure.



ralphbsz said:


> You claim to know the C language. How many ten thousand lines of C have you written, which went into production, ran bug-free and which were reviewed by colleagues?


I wanna write a lot of code, but don't know how to end up as an expert, and I feel kind of blind walking to nowhere. I'm a self-taught programmer, who want one day get hired by a company. Though, I don't to think that the only way to become an expert in this, is by getting hired by a company. Somewhere should be all kind of path in, to get there, as a self-taught.



ralphbsz said:


> For learning how a real-world kernel works, I don't think there is a better book than the daemon book: Design and Implementation of BSD, by McKusick and friends. Get it, and read it 10 times. Try to get your copy autographed by Kirk (mine isn't, which really annoys me).


I'll try to get it and read it forever, untill It's useless.


ralphbsz said:


> But all that will not make you a kernel programmer. Programming in the kernel requires first considerable C programming experience, and then a lot of special attention and care. If you are serious about it, and have met the preconditions, then download the source, and start improving something random. For example, find bugs on the FreeBSD bug tracking system, and fix them.


C programming experience? Writing... software that run on top of the kernel? What kind of software do you recommend to start, and follow through with? I hope the path it's not that's so long, that takes forever... I wish I could build an instant messaging app in C one day as well. To me it's interesting in C.

Thank you for the reply.


----------



## helmet1080 (Mar 12, 2019)

pyret said:


> I would be remiss if a few other additions are not added.  They will be considered outside of the mainstream, but are excellent as teaching tools.
> 
> Xv6, a simple Unix-like teaching operating system is used at MIT for their operating systems course.  You can build it from source and there is a free book available.  Russ Cox was instrumental in developing Xv6 and he also worked on Plan 9 at Bell Labs.
> 
> ...


 I read the read. Very inspirational read. 
So many options, and I'll probably take the free book. Thank you.


----------



## ralphbsz (Mar 12, 2019)

helmet1080 said:


> I'll try to get it and read it forever, untill It's useless.


Thank you for your sense of humor.



> Writing... software that run on top of the kernel? What kind of software do you recommend to start, and follow through with?


That's a good starting point.  But beware that there is a lot more to the craft, art and science of software engineering than programming in C.  I would actually recommend learning how to program in a much easier language (python, java, or one of the simplified programming languages used for education).  That gives the basic skills of writing good and structured code.  Then learn OOA&D.  Then learn software engineering workflows and engineering practices.  Only start programming in C once you have developed the good taste of knowing how to structure the code.


----------



## helmet1080 (Mar 12, 2019)

ralphbsz said:


> Thank you for your sense of humor.
> 
> 
> That's a good starting point.  But beware that there is a lot more to the craft, art and science of software engineering than programming in C.  I would actually recommend learning how to program in a much easier language (python, java, or one of the simplified programming languages used for education).  That gives the basic skills of writing good and structured code.  Then learn OOA&D.  Then learn software engineering workflows and engineering practices.  Only start programming in C once you have developed the good taste of knowing how to structure the code.


I know the basics of Python and the OOP. It's a good language. I'm gonna keep going with Python and aside, learn Operating System Concepts. Just to make the journey more interesting and fun. Thank you for your advice.


----------



## SirDice (Mar 13, 2019)

helmet1080 said:


> I wanna write a lot of code, but don't know how to end up as an expert, and I feel kind of blind walking to nowhere.


You become an expert by doing it. Not reading about it, actually doing the work. Solve real world problems. Run into issues, debug code until the sun starts coming up again. Ponder on solutions for days on end. Nobody became an coding wizard  just by reading books. Books provide lots of theoretical information, experts know how to translate that theory into something practical that works in the real world. 



helmet1080 said:


> I'm a self-taught programmer, who want one day get hired by a company.


That's good. Start at the bottom and work your way up. That's how you become an expert at something.


----------

