LinuxQuestions.org
Visit Jeremy's Blog.
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-03-2014, 03:31 PM   #1
heggo
LQ Newbie
 
Registered: Apr 2014
Posts: 5

Rep: Reputation: Disabled
Disadvantages of using system calls


Hi

are there any disadvantages (e.g. in terms of performance or otherwise) in using system calls, as opposed to using direct bindings made for a programming language?

In particular, I have in mind the management of extended attributes (xattr).

Thanks
 
Old 04-03-2014, 07:29 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

portability is a potential problem. What language are you using and what platform(s) is the code supposed to run on?

Evo2.
 
Old 04-03-2014, 08:39 PM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
For most things, you can find useful "prior art" that you can use in your program. For example, a quick Google on "how to use extended attributes in C++" pointed me, say, to http://www.lesbonscomptes.com/pxattr/.

No matter what it is that you're doing, someone usually has done it before, and has "wrapped up the dirty messy smelly guts of how to do it" in a nice piece of fish-paper. It's well worth looking for such things.

"Performance" and so-forth is going to be irrelevant, because "whatever-it-is that the routine actually does" will very quickly zero-in on "the necessary system call(s), and nothing more." You're simply looking for convenience, robustness, the ability to leverage someone else's instead of your own, and to stay as much as possible within the paradigm of your particular programming language.

"Do not do a thing already done."
 
Old 04-04-2014, 04:49 AM   #4
heggo
LQ Newbie
 
Registered: Apr 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
What language are you using and what platform(s) is the code supposed to run on?
The Language is FreePascal, and the program is supposed to run on Linux.


Quote:
For most things, you can find useful "prior art" that you can use in your program. For example, a quick Google on "how to use extended attributes in C++" pointed me, say, to http://www.lesbonscomptes.com/pxattr/.

No matter what it is that you're doing, someone usually has done it before, and has "wrapped up the dirty messy smelly guts of how to do it" in a nice piece of fish-paper. It's well worth looking for such things.
Yes, I know. I have already asked for previous solutions on the FreePascal/Lazarus forum. All I got is the advice of using the Linux system call.
Actually I was looking for a direct binding for the Language, assuming that it would be faster. Functionally, the system call should be good enough, in the sense that it works.
My question on this forum was precisely whether I should be satisfied with using the system call, or twhether I should keep looking for a binding, although in the case of FreePascal non previous bindings are available.

In case the "system call" solution is good enough (without too much overhead on performance), then I would stop searching for an alternative and simply use it.

Quote:
"Performance" and so-forth is going to be irrelevant, because "whatever-it-is that the routine actually does" will very quickly zero-in on "the necessary system call(s), and nothing more."
My assumption (which may be wrong, course) was that the system call itself could entail some delay, and that a binding that bypasses the system call might be faster. Is that so?
 
Old 04-04-2014, 04:51 AM   #5
heggo
LQ Newbie
 
Registered: Apr 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by evo2 View Post
Hi,

portability is a potential problem
So, do you mean that using system calls is a better solution, for the sake of portability?

Last edited by heggo; 04-04-2014 at 04:52 AM.
 
Old 04-04-2014, 09:01 AM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
No, I think that the suggestion is that you should either obtain or construct a module within your program whose interface represents, well, "what does it do?" (And whose implementation, then, encapsulates: "how does one do it?")

This module will carry out the system-calls to do its work. But it prevents those system-calls (hence: "system-specific how-to-do-its") from proliferating throughout the rest of the program's source code.

Hence, if the program ever needed to be ported, only that one module would have to change. (And, there would be only one place in the program where someone would have to be staring at a manual concerning those system-calls while trying to add a new feature or to chase down a bug.)

"Performance" is a non-issue here. "Maintainability," however, is a ruling concern, and this strategy will do a lot to preserve that.
 
Old 04-04-2014, 10:14 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
No need to avoid system calls but don't use them if you don't need to.
If your language has constructs or libraries that do what you want then it's probably advisable to use them.

Efficiency of one or the other is moot.
 
Old 04-05-2014, 11:04 AM   #8
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 heggo View Post
So, do you mean that using system calls is a better solution, for the sake of portability?
He meant that using system calls reduces portability.
 
Old 04-05-2014, 12:56 PM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Please give a few examples, what system calls you intend to 'use directly'.
 
Old 04-15-2014, 07:10 AM   #10
heggo
LQ Newbie
 
Registered: Apr 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
Please give a few examples, what system calls you intend to 'use directly'.
I must say am not very expert of these things, that's why I am asking you guys.
What I had in mind was having a direct binding for the setxattr and getxattr commands, from withing the programming language, accessing directly the relevant library. As pointed out, the same end result can be easily accomplished via system calls, which are supported by most programming languages.
My doubt was only about the possible disadvantages.

BTW what would be the relevant library for those two commands?
 
Old 04-15-2014, 07:11 AM   #11
heggo
LQ Newbie
 
Registered: Apr 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by heggo View Post
I must say am not very expert of these things, that's why I am asking you guys.
What I had in mind was having a direct binding for the setxattr and getxattr commands, from within the programming language, accessing directly the relevant library. As pointed out, the same end result can be easily accomplished via system calls, which are supported by most programming languages.
My doubt was only about the possible disadvantages.

BTW what would be the relevant library for those two commands?

Thanks

Last edited by heggo; 04-15-2014 at 07:12 AM.
 
Old 04-15-2014, 08:06 AM   #12
prushik
Member
 
Registered: Mar 2009
Location: Pennsylvania
Distribution: gentoo
Posts: 372

Rep: Reputation: 29
Quote:
Originally Posted by heggo View Post
What I had in mind was having a direct binding for the setxattr and getxattr commands, from within the programming language, accessing directly the relevant library. As pointed out, the same end result can be easily accomplished via system calls, which are supported by most programming languages.
My doubt was only about the possible disadvantages.

BTW what would be the relevant library for those two commands?

Thanks
System calls will be faster than using library functions, which I think is what you mean by "direct binding". Your "binding" will just be making the system calls anyway, but there will be added overhead for the function calls and whatever else the functions might do, such as error checking.
If you are only planning to run on Linux, then using system calls shouldn't result in much portability problems except in rare cases.

However, the performance gains will be very small, and most programmers wouldn't bother with making syscalls because for one thing, many programmers don't understand the OS at that level and for another thing because it is harder. Other people might cite portability and maintainability as disadvantages, and its true somewhat, but there is always debate.

In your case, I say go ahead with the syscalls if you can do it. Your performance will not suffer, in fact, it will be marginally better, but probably not noticeable. If you plan to run your software on something like, say, OSX, then you might run into problems.
 
Old 04-15-2014, 08:16 AM   #13
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
My Debian 6 is a bit oldish, so I cannot tell what setxattr/getxattr is good for; but I'm quite sure that using them (either via function-call or INT 0x80) will make your program platform-dependent.
 
Old 04-15-2014, 09:02 AM   #14
prushik
Member
 
Registered: Mar 2009
Location: Pennsylvania
Distribution: gentoo
Posts: 372

Rep: Reputation: 29
Quote:
Originally Posted by NevemTeve View Post
My Debian 6 is a bit oldish, so I cannot tell what setxattr/getxattr is good for; but I'm quite sure that using them (either via function-call or INT 0x80) will make your program platform-dependent.
Also filesystem dependent. Not all file systems support extended attributes and/or may be disabled (hence the "extended" part).
 
Old 04-15-2014, 09:33 AM   #15
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Quote:
Originally Posted by prushik View Post
In your case, I say go ahead with the syscalls if you can do it. Your performance will not suffer, in fact, it will be marginally better, but probably not noticeable. If you plan to run your software on something like, say, OSX, then you might run into problems.
... whereas I would respectfully dissent, and say to the OP: "if you find a saddle, ride in it, instead of trying to hang-on to the back of the horse." System calls are really designed to be the lowest level interface. There's a lot of stuff that is "ordinarily needed" that has already been built on-top of that layer, in the form of standard system libraries ... both those that are included with the language and those that are not. To me, it's senseless to reinvent any wheel at all. There's no "up-side" to doing it, it takes many hundreds of thousands of microseconds to add-up to the blink of an eye, and there could be a "down-side," therefore ... "why (bother)?"
 
  


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
how does java calls the system calls which are written in c babu198649 Linux - General 3 12-05-2011 03:40 AM
system calls ashish anand Linux - Embedded & Single-board computer 1 07-17-2011 03:01 PM
What are the disadvantages of using a 64 bit system? drmjh Linux - General 13 07-08-2009 10:30 AM
system calls with C khodeir Programming 4 03-12-2009 08:26 PM
Some system calls Spooky Programming 1 11-24-2004 10:17 AM

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

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