Login or Register to Ask a Question and Join Our Community


Inappropriate ioctl for device


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inappropriate ioctl for device
# 1  
Old 05-28-2013
Inappropriate ioctl for device

Sample program tty, this will be get called from my script test_script.

Code:
#include <stdio.h>
#include <unistd.h>
#define TTY_NAME_MAX        32
#define STDIN_FILENO    0   /* Standard input.  */

int main(void) {
    int     ret = 0;
    char    local_device_file[TTY_NAME_MAX];
        printf("\npid = %d\n",getpid());
        ret = ttyname_r(STDIN_FILENO, local_device_file, TTY_NAME_MAX);
        printf("ret = %d, local_device_file = %s\n",ret,local_device_file);
        return 0;
}

--------------------------------------------------------------------
Working condition:

test_script:
Code:
echo "running test script"
/users/ghonnaia/tty

Output:
Code:
bgl-xdm-140:199> ./test_script
running test script
pid = 6249
ret = 0, local_device_file = /dev/pts/399

--------------------------------------------------------------------
Fail Condition:

test_script:
Code:
echo "running test script"
/users/ghonnaia/tty &


Output:
Code:
bgl-xdm-140:197> ./test_script
running test script
bgl-xdm-140:198> 
pid = 5951
ret = 25, local_device_file =

Return value 25 means Inappropriate ioctl for device.

Can anyone please explain me why this error comes when we make saple program to run in backgound in a script.

Thanks,
Gajendra

Moderator's Comments:
Mod Comment edit by bakunin: please use CODE-tags, as is specified in our rules. Thank you.

Last edited by bakunin; 05-28-2013 at 11:03 AM..
# 2  
Old 05-28-2013
Quote:
Originally Posted by Gajendra_PH
Can anyone please explain me why this error comes when we make saple program to run in backgound in a script.
Because a background program doesn't control the terminal, only the foreground.
# 3  
Old 05-28-2013
I disagree with Corona688. Being in the foreground or background shouldn't affect what ioctl's a device supports.

It is my belief that the cause of the malfunction is that STDIN is not a terminal because the shell is redirecting STDIN from /dev/null when it runs the process (or pipeline) in the background.

Quote:
Originally Posted by POSIX
The standard input for an asynchronous list, before any explicit redirections are performed, shall be considered to be assigned to a file that has the same properties as /dev/null. If it is an interactive shell, this need not happen. In all cases, explicit redirection of standard input shall override this activity.
I don't know what system you're running, but on a circa 2007 Debian Linux install, /usr/include/asm-generic/errno-base.h (which is the ultimate destination of the #include breadcrumb trail beginning at /usr/include/errno.h) has this to say:
Code:
#define ENOTTY          25      /* Not a typewriter */

Regards,
Alister
# 4  
Old 05-28-2013
Yes I too agree with alister...only a foreground process can read from the terminal preventing multiple processes from competing for terminal input as there's only one process in the foreground at any instant...
# 5  
Old 05-28-2013
Quote:
Originally Posted by shamrock
..only a foreground process can read from the terminal preventing multiple processes from competing for terminal input as there's only one process in the foreground at any instant...
To be more precise, any process in the foreground process group can read from the terminal, and there can be many of them in that group.

Regards,
Alister
# 6  
Old 05-29-2013
Thanks you all for replying with good information. Now I understand the problem and will avoid calling the app in background.

Alister, I'm using a customized Linux OS for embedded application.

#define ENOTTY 25 /* Inappropriate I/O control operation */

Regards,
Gajendra

Last edited by Gajendra_PH; 05-29-2013 at 01:59 AM.. Reason: word change
# 7  
Old 05-30-2013
You can call it in the background, but to keep the tty as standard input requires overriding the shell's redirection. Note that if the process tries to read while not in the foreground process group, it will be signaled and put to sleep.

Not knowing what you are trying to achieve, it's impossible to say if I just gave you good or bad advice. Still, I wanted to mention that it is possible to workaround this ENOTTY.

Regards,
Alister

Last edited by alister; 05-30-2013 at 01:36 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Tcgetattr: Inappropriate ioctl for device

Hi, ssh -q -t -l $usr $host bin/test.sh I am using above command to run script remotely. script is working without any issues. but I am getting "tcgetattr: Inappropriate ioctl for device" message on console. plz help how can I avoid this message. Thanks Moved thread from Emergency... (1 Reply)
Discussion started by: Kri
1 Replies

2. UNIX for Advanced & Expert Users

nohup: can't detach from console: Inappropriate ioctl for device

Hi! I am getting a nohup issue on mac osx while trying to start a process through nohup in the startup script. nohup: can't detach from console: Inappropriate ioctl for device Please help! Thanks, Allan. (0 Replies)
Discussion started by: jacki
0 Replies

3. Shell Programming and Scripting

tcgetattr: Inappropriate ioctl for device after ssh command

Hello everyone I am finishing a script allowing me to purge logs on multiple servers, i have one last pb with the ssh command.........it is throwing me the following error : tcgetattr: Inappropriate ioctl for device (full screen in attached file 1, full script in attached file 2) It... (15 Replies)
Discussion started by: jimmy75_13
15 Replies

4. Shell Programming and Scripting

hdparm + Inappropriate ioctl for device

Hi All, Am finding performance of my SD card using hdparm. Code: hdparm -tT /dev/BlockDev0 /dev/BlockDev0: Timing cached reads: 1118 MB in 2.00 seconds = 558.61 MB/sec HDIO_DRIVE_CMD(null) (wait for flush complete) failed: Inappropriate ioctl for device Timing buffered disk... (1 Reply)
Discussion started by: amio
1 Replies

5. UNIX for Dummies Questions & Answers

mt command shows /dev/tape: inappropriate ioctl for device

Hello guys, on my Red Hat machine the /bin/mt status command gives the output dev/tape: inappropriate ioctl for device. This messages comes up after the Server has been rebooted. Anybody an idea? Thx masterofdesaster (8 Replies)
Discussion started by: masterofdesaste
8 Replies

6. Shell Programming and Scripting

Inappropriate ioctl for device

Dear all, Problem goes like this: I have a shell script which when run manually runs perfectly. When same script is executed through a job schdeduler I get an error as Inappropriate ioctl for device and the script fails. This problems seems quite guiling to me. Any clues are heartly... (11 Replies)
Discussion started by: RishiPahuja
11 Replies

7. Solaris

Inappropriate ioctl for device, format error

When I try to format a slice in Solaris 10 I get the follow error : -bash-3.00# mkfs /dev/dsk/c1d0s5 18877824 Can not determine partition size: Inappropriate ioctl for device Some format command output:.... AVAILABLE DISK SELECTIONS: 0. c1d0 <DEFAULT cyl 38735 alt 2 hd 64 sec 63>... (2 Replies)
Discussion started by: spoonman
2 Replies

8. UNIX for Dummies Questions & Answers

Inappropriate ioctl for device

Hello, I have a cron entry: 59 23 * * * . $HOME/.profile;mydate=`date '+%Y%m%d'`;mv filename filename_$mydate Which works fine interactively, but gives me the following error when it runs in cron: Your "cron" job on servername . $HOME/.profile;mydate=`date '+ produced the... (4 Replies)
Discussion started by: steelrose
4 Replies

9. UNIX for Dummies Questions & Answers

Inappropriate ioctl for device

When I try to format a slice in Solaris 10 I get the follow error :confused: : -bash-3.00# mkfs /dev/dsk/c1d0s5 18877824 Can not determine partition size: Inappropriate ioctl for device Some format command output:.... AVAILABLE DISK SELECTIONS: 0. c1d0 <DEFAULT cyl 38735 alt 2... (0 Replies)
Discussion started by: spoonman
0 Replies

10. Filesystems, Disks and Memory

Inappropriate ioctl for device

Hi, We are running a perl script to upload some data using SQL* Loader. We pipe the data in a http request to SQL*Loader which loads the data to the database. We encounter the error "Inappropirate ioctl for device" when we try to upload huge data. Any solution would be greatly appreciated.... (4 Replies)
Discussion started by: tojaiganesh
4 Replies
Login or Register to Ask a Question

Featured Tech Videos