Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Hardware
User Name
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?


  Search this Thread
Old 07-30-2003, 08:43 AM   #1
LQ Newbie
Registered: Aug 2001
Location: New Jersey
Distribution: Red Hat
Posts: 6

Rep: Reputation: 0
Question I need a real Linux genius for this one.


Brief description of problem:
I am running a tiny C program to control the output on the parallel port. It runs on some machines, but on others, I get a Segmentation Fault.

Full Description:
I have a problem with my DSL line going down, so I used the coffee how-to and some other sites to construct a circuit that hooks up to the parallel port and drives a relay to cut power to the dsl modem. I am using a very tiny C program listed below.
I tested the program and circuit on a laptop under RedHat8 and it works perfectly. However when I compile and run the C program on either of two desktops running RedHat9 it exits with a Segmentation Fault. I need help in getting this to work.

Here is the Kernel Message defining the parallel port:

Jun 27 07:09:50 ksix kernel: parport0: PC-style at 0x378 (0x778) [PCSPP,TRISTATE]
Jun 27 07:09:51 ksix kernel: parport0: irq 7 detected

Here is the C program:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <asm/io.h>

#define base 0x378 /* printer port base address */

main(int argc, char **argv)
int value;

if (argc!=2)
fprintf(stderr, "Error: Wrong number of arguments. This program needs one argument which is number between 0 and 255.\n"), exit(1);
if (sscanf(argv[1],"%i",&value)!=1)
fprintf(stderr, "Error: Parameter is not a number.\n"), exit(1);
if ((value<0) || (value>255))
fprintf(stderr, "Error: Invalid numeric value. The parameter number must be between 0 and 255\n"), exit(1);
if (ioperm(base,1,1))
fprintf(stderr, "Error: Couldn't get the port at %x\n", base), exit(1);

outb((unsigned char)value, base);

Old 07-30-2003, 08:47 AM   #2
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
have you tried adding debugging print statements to it to track down where this segfault occurs?
Old 07-30-2003, 01:40 PM   #3
Registered: Apr 2002
Location: Bronx, NY
Distribution: Ubuntu
Posts: 364

Rep: Reputation: 33
Different approach. Instead of trying to push to the actual CPU Port (which may be fine) - why not push directly to the device.

port = fopen("/dev/parport0", "w");
fputc(port, (unsigned int)value);

Obviously more error checking, but basically forget trying to get directly to it.
Old 08-04-2003, 09:08 AM   #4
LQ Newbie
Registered: Aug 2001
Location: New Jersey
Distribution: Red Hat
Posts: 6

Original Poster
Rep: Reputation: 0
I don't think it's a C problem, I think it's an OS related problem, because that code works on other boxes. I tried
GAVollink's suggestion and it doesn't throw a Segmentation Fault, but at the same time it also does not set the pins of the parallel port.

At one time I had a printer hooked up to this box. That leads me to guess that something is still holding control of the parallel port. So when I try to write to it, I get a Seg Fault, because some other process is already holding that memory location. However this is just a guess, and I don't know how to tell is something is holding that port.
Old 08-04-2003, 12:31 PM   #5
King of Japan
Registered: Jul 2003
Location: Lincoln Nebraska
Distribution: Redhat 9
Posts: 61

Rep: Reputation: 15
This may or may not help at all, but there is something messed up with the Parallel port stuff at the Kernel level of the original Rh9 distro. I could not get a Parallel port Zip drive to work for the life of of me. It worked fine on Rh7.2 and on Rh8 but would not work on Rh9. Finally someone else told me that I should update the Kernel to:


Found here:

after that, it mounted like it should have.

anyhoo, it's just a thought.
Old 08-07-2003, 11:46 AM   #6
LQ Newbie
Registered: Aug 2001
Location: New Jersey
Distribution: Red Hat
Posts: 6

Original Poster
Rep: Reputation: 0
That's it. It works!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Genius Webcam NB jalal Linux - Hardware 2 09-11-2006 06:36 PM
Real Plyer...hehe ;) Giving me Real Problems.. Azzath Linux - Software 0 02-14-2005 08:56 AM
dual display question - real real newbie !! Jay_Dee007 Linux - Newbie 1 09-29-2003 08:33 AM
Figure this out and you're a genius Duren Linux - Hardware 8 09-13-2003 02:43 PM
Real Programmers Real People Real CS Students nakkaya General 5 07-04-2003 02:46 PM > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 01:13 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration