09-30-2004
unix system programming
hey there
i have to execute commands that are written on the command line in unix. i have already separated the commands into tokens but now im stuck with the problem of how to actually execute those commands.
eg: lets say the user entered " ls -l" to list all the files in a directory
pid_t pid;
if ( (pid = fork()) < 0)
fprintf(stderr,"fork error");
else if (pid == 0) { /* child */
// NOW WHAT GOES HERE ????
}
feedback would be appreciated.
thanks
mile1982
10 More Discussions You Might Find Interesting
1. Programming
Hi there,
Am very very interested in system level programming in C????
Please give me a good site or a sample program to start with..
will be of a great help to me..
Thanks,
Nisha (7 Replies)
Discussion started by: Nisha
7 Replies
2. Shell Programming and Scripting
Several months ago I found a link that explained the difference between how a Unix Systems Admin would do scripting compared to what a Unix Programmer would do.
It showed a basic script and then show several iterations that explained how the Systems Admin would change it to make it better. I was... (0 Replies)
Discussion started by: BCarlson
0 Replies
3. UNIX for Dummies Questions & Answers
this is very urgent plzzzzzzzzzzzzzzzz........... (0 Replies)
Discussion started by: stalin2020
0 Replies
4. UNIX for Dummies Questions & Answers
Hello,
I am trying to learn Networking Programming in C in unix enviorment. I want to know how good it is to become a network programmer. i am crazy about Network programming but i also want to opt for the best carreer options. Anybody experienced Network Programmer, please tell me is my... (5 Replies)
Discussion started by: vibhory2j
5 Replies
5. Programming
Hi,
I've almost finished "Advanced Linux Programming" book. However, I feel as if I need dig deeper in IPC specially socket programming as well as multi-threading. Can anyone recommend a good book (preferably publically available)? (5 Replies)
Discussion started by: jaywalker
5 Replies
6. UNIX for Dummies Questions & Answers
How does unix system administration, unix programming, unix network programming differ?
Please help. (0 Replies)
Discussion started by: thulasidharan2k
0 Replies
7. Programming
Hi friends,
Hope u r doing well. I really find the phrase, "Unix System Programming" very very cool, I don't know the reason, but it since I love UNIX, I want to do system programming in unix. Could you please tell me what is really the meaning of unix system programming. I have a couple of books... (5 Replies)
Discussion started by: gabam
5 Replies
8. Shell Programming and Scripting
Hi All
I want to learn System programming with the help of Unix.
System Programming mean to say
1) Playing with the memory of computer
2) Designing some graphical units
Hope you understand... (2 Replies)
Discussion started by: parthmittal2007
2 Replies
9. UNIX for Dummies Questions & Answers
Hello.
I like Linux and C programming language. Allways wanted to understand kernel and become a Linux system programmer. And I also like Objective-C and iOS. These two programming areas have relations:
1. Linux and iOS are UNIX-like systems, POSIX compliant.
2. It is useful to know C language... (2 Replies)
Discussion started by: Rockatansky
2 Replies
10. UNIX for Advanced & Expert Users
Hi,
I was working in an IT firm. My stream was UNIX, C, C++.
worked for an year and half and then left the job.
there has been a gap of 2 years already and wanna get back again. i have some 6 more months to that. want to do some certification to help me get back.
c,c++ are fine. unix system... (1 Reply)
Discussion started by: niaR
1 Replies
LEARN ABOUT OSF1
bind_to_cpu
bind_to_cpu(3) Library Functions Manual bind_to_cpu(3)
NAME
bind_to_cpu - Bind execution to a specific CPU.
LIBRARY
Mach Library (libmach.a)
SYNOPSIS
#include <sys/types.h> #include <sys/resource.h>
int bind_to_cpu(
pid_t pid,
unsigned long cpu_mask ,
unsigned long flag );
PARAMETERS
Specifies the target pid. You must have access rights to the pid. Specifies the CPU on which the thread should run. The target CPU is the
bit index in the mask. If you set more than one bit, an error is generated. A cpu_mask of zero clears any previously set CPU binding.
Specifies options to CPU binding. Currently only the option BIND_NO_INHERIT is supported. When set, this option causes child processes
and threads to not inherit the CPU binding.
DESCRIPTION
Upon return from bind_to_cpu, all threads of the target pid are running on the target CPU. Bound threads are not eligible for execution on
any other CPU. You release CPU binding by invoking bind_to_cpu with a cpu_mask of zero.
EXAMPLES
/*
* Fork child process and force it to run on cpu number 3.
* Processes created by the forked child will not inherit bindings.
*/ #include <sys/resource.h> #include <sys/sysinfo.h> #include <sys/signal.h> #include <sys/types.h>
#define CPU_3 0x8 /* Bit 3 set */
main() {
pid_t pid;
if (pid = fork()) { /* parent */
if (bind_to_cpu(pid, CPU_3, BIND_NO_INHERIT)) {
kill(pid, SIGKILL);
exit(1); /* bind_to_cpu() will print error msg */
}
sleep(2); /* wait for child to print CPU */
}
else { /* child */
long cpu_num;
sleep(1); /* wait for parent to bind CPU */
getsysinfo(GSI_CURRENT_CPU, &cpu_num, 0L, 0L, 0L);
printf("child running on CPU %d
", cpu_num);
} }
In this example, the CPU_3 symbol is defined so that bit three in the bit mask is set. When the pid returned from the fork routine identi-
fies the parent routine, the bind_to_cpu routine is called. This routine binds the child process to CPU number three, as specified in the
CPU_3 symbol. When the pid returned from the fork routine identifies the child routine, the child routine sleeps to give the parent routine
time to set its CPU binding. Then it uses the getsysinfo call to determine its CPU and displays its CPU with the printf routine.
If the return value from the bind_to_cpu routine indicates an error, the parent process kills the child process and exits with an error
status.
RETURN VALUES
Upon successful completion, bind_to_cpu returns zero. Upon error, a -1 is returned.
RELATED INFORMATION
Commands: runon(1)
Functions: getsysinfo(2) delim off
bind_to_cpu(3)